មេរៀនទី១២៖ Digital Read

Digital Read

 

1. Objective

The objective is talk about, how to use digital read to control LED.

2. Requirement

  • Arduino Uno x1
  • USB Cable x1 (No need in simulation)
  • Breadboard x1 (No need in simulation)
  • LED x2
  • Resistor (220Ohm or 330Ohm) x2
  • Electronic Wire (No need in simulation) 
  • Button x1

 

3. Build Circuit

Build circuit like Figure 1.


Figure 1: Arduino Connection

 

4. Coding

// Tann Thona
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(2, INPUT);

}

void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(2) == 1)
{
digitalWrite(13, 1); // HIGH is the same value 1
digitalWrite(12, 0); // LOW is the same value 0
}
else
{
digitalWrite(13, 0); // LOW is the same value 0
digitalWrite(12, 1); // HIGH is the same value 1
}

}

Click Here to Download Code and Proteus Simulation File 

 

4. Result

According to code above, if we press button one LED is bright and one dark. When we release button this two LED was switching bright and dark.


Watch Video Explain in Khmer





YouTube: ICT4D-KH
Copyright By Tann Thona



Post a Comment

0 Comments