keyestudio
Sample program
In the program compiling process, we will use the analogWrite (PWM interface, analog value)
function. In this experiment, we will read the analog value of the potentiometer and assign the
value to PWM port, so there will be corresponding change to the brightness of the LED. One final
part will be displaying the analog value on the screen. You can consider this as the "analog value
reading" project adding the PWM analog value assigning part. Below is a sample program for
your reference.
//////////////////////////////////////////////////////////
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()
{
www.keyestudio.cc
25
Need help?
Do you have a question about the ARDUINO maker learning kit and is the answer not in the manual?