
keyestudio
www.keyestudio.com
39
Connection for 2560 R3:
Sample Code
After wiring, let's begin the program compiling. The program is similar to the PWM.
For change detail, please refer to the Sample Code below.
//////////////////////////////////////////////////////////
int potpin=0;// initialize analog pin 0, connected with photovaristor
int ledpin=11;// initialize digital pin 11, output regulating the brightness of LED
int val=0;// initialize variable va
void setup()
{
pinMode(ledpin,OUTPUT);// set digital pin 11 as “output”
Serial.begin(9600);// set baud rate at “9600”
}
void loop()
{
val=analogRead(potpin);// read the analog value of the sensor and assign it to val
Serial.println(val);// display the value of val
analogWrite(ledpin,val/4);// turn on the LED and set up brightness
(
maximum output value 255
)
Summary of Contents for KS0077
Page 1: ...keyestudio www keyestudio com 1 Super Learning Kit for Arduino...
Page 14: ...keyestudio www keyestudio com 14 Connection for UNO R3 Connection for 2560 R3...
Page 32: ...keyestudio www keyestudio com 32 Connection for 2560 R3...
Page 42: ...keyestudio www keyestudio com 42 Connection for MEGA 2560...
Page 45: ...keyestudio www keyestudio com 45 Connection for UNO R3 Connection for 2560 R3...
Page 59: ...keyestudio www keyestudio com 59 Connection for 2560 R3...
Page 66: ...keyestudio www keyestudio com 66 Connection for 2560 R3...
Page 72: ...keyestudio www keyestudio com 72 Manual for LED Segment Display Connection for UNO R3...
Page 85: ...keyestudio www keyestudio com 85 8 bit Connection Method Connection for UNO R3...
Page 94: ...keyestudio www keyestudio com 94 Connection for 2560 R3 Connect the motor to digital pin 9...