EasyManua.ls Logo

Keyestudio KS0077 - Page 48

Keyestudio KS0077
142 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
keyestudio
www.keyestudio.com
48
Connection for 2560 R3:
Connect the controller board, shield, breadboard and USB cable according to Arduino tutorial.
Connect the LED to digital pin 8, ball switch to analog pin 5.
Experiment Principle
When one end of the switch is below horizontal position, the switch is on. The voltage of the
analog port is about 5V (1023 in binary). The LED will be on. When the other end of the switch is
below horizontal position, the switch is off. The voltage of the analog port is about 0V (0 in
binary). The LED will be off. In the program, we determine whether the switch is on or off
according to the voltage value of the analog port, whether it's above 2.5V (512 in binary) or not.
Sample Code
//////////////////////////////////////////////////////////
void setup()
{
pinMode(8,OUTPUT);// set digital pin 8 as “output”
}
void loop()
{
int i;// define variable i