Advertisement
learnelectronics

Arduino for Kids - Party Strobe Light

Aug 2nd, 2017
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. /*
  2.  * Arduino for Kids - Party Strobe Light
  3.  *
  4.  * learnelectronics
  5.  * 31 JUL 2017
  6.  *
  7.  * www.youtube.com/c/learnelectronics
  8.  */
  9.  
  10. #define mosfet  5                                   //MOSFET gate on digital pin 5
  11. #define pot     A0                                  //wiper from potentiometer on analog pin 0
  12.  
  13. int wait = 0;                                       //ultimate delay time
  14.  
  15.  
  16. void setup() {
  17.  
  18.   pinMode(5,OUTPUT);                                //digital pin 5 set for output
  19.   pinMode(A0,INPUT);                                //analog pin 0 set for input
  20.   Serial.begin(9600);                               //begin serial comms for debuging
  21.  
  22. }
  23.  
  24. void loop() {
  25.  
  26.   int pRead = analogRead(pot);                      //begin each loop by reading the position of the pot
  27.   wait = map(pRead,0,1023,100,2000);                //map the analog read to a value between 100mS to 2 seconds
  28.  
  29.   Serial.print(pRead);                                //send variables to serial monitor for debugging
  30.   Serial.print("-->");
  31.   Serial.println(wait);                             //send variables to serial monitor for debugging
  32.  
  33.   digitalWrite(mosfet,HIGH);                        //flash the MOSFET
  34.   delay(100);                                       //wait 100mS
  35.   digitalWrite(mosfet,LOW);                         //shut off the MOSFET
  36.   delay(wait);                                      //wait for the time specified in the wait variable
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement