Keyestudio KS0436 Kit Manual page 50

Table of Contents

Advertisement

50
1) Connect the
REV4
Board to a USB port on your computer.
Upload Code:
2) Open the program in the code folder- Circuit 3 Potentiometer, or
directly copy and paste the code below on the Ardunio IDE.
3) Select UPLOAD to program the sketch on the UNO Board.
int potpin=0;// initialize analog pin 0
int ledpin=11;//initialize digital pin 11(PWM output)
int val=0;// Temporarily store variables' value from the sensor
void setup()
{
pinMode(ledpin,OUTPUT);// define digital pin 11 as "output"
Serial.begin(9600);// set baud rate at 9600
// attention: for analog ports, they are automatically set up as "input"
}
void loop()
{
val=analogRead(potpin);// read the analog value from the sensor and
assign it to val
Serial.println(val);// display value of val
analogWrite(ledpin,val/4);// turn on LED and set up brightness
(maximum output of PWM is 255)

Advertisement

Table of Contents
loading

Table of Contents