Download Print this page

sparkfun Tinker Kit Experiment Manual page 13

Advertisement

/* SparkFun Tinker Kit  
Example sketch 02 
POTENTIOMETER 
  Measure the position of a potentiometer and use it to 
  control the blink rate of an LED. Turn the knob to make 
  it blink faster or slower! 
This sketch was written by SparkFun Electronics, 
with lots of help from the Arduino community. 
This code is completely free for any use. 
Visit http://learn.sparkfun.com/products/2 for SIK informatio
n. 
Visit http://www.arduino.cc to learn about Arduino. 
*/
//Create global variables (variables that can be used anywher
e in our sketch)
// Here we're creating a variable called "sensorPin" of type 
"int"
// and initializing it to have the value "0," which is the ana
log input pin the pot is     //conected to.
int sensorPin = 0;    
// Variable for storing the pin number that the LED is connect
ed to                 
int ledPin = 13;      
// this function runs once when the sketch starts up
void setup() 
//set ledPin (13) as an OUTPUT
pinMode(ledPin, OUTPUT);
// this function runs repeatedly after setup() finishes
void loop() 
//create a local variable (variable that can only be used in
side of loop() to store       //a sensor value called sensorVa
lue
int sensorValue;
//use the analogRead() function to read sensorPin and store 
the value in sensorValue
  sensorValue = analogRead(sensorPin);    
// Turn the LED on
digitalWrite(ledPin, HIGH);     
delay(sensorValue);             
// Turn the LED off
digitalWrite(ledPin, LOW);      
//delay for the value of sensorValue
delay(sensorValue);             
Page 13 of 63

Advertisement

loading
Need help?

Need help?

Do you have a question about the Tinker Kit and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Kit-14556Kit-14556-ndKit-13930