Advertisement
westin

Arduino Power Hour Revisited

Apr 12th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. /* A revamped power hour sketch.  One shot of bee... I mean soda
  2. every minute for an hour [every time the speaker beeps]. -- Hook an 8 ohm speaker to pin 8 on the
  3. arduino.  This sketch will increase the pitch of the tone with each drink.  This will kind of give you an idea of where you are in the hour.  It also buzzes twice at the end, signifying that you are done.  
  4.  
  5. Originally written by Weston George - Use it, change it, share it...*/
  6.  
  7. int pitch = 300; // Set initial Pitch to 300hz.
  8. int audioPin = 8; // Set audio pin to 8.
  9. int counter = 0; // Set counter at 0.
  10.  
  11. void setup(){
  12. }
  13.  
  14. void loop(){
  15.   counter = (counter + 1); // Increment the counter by 1 each time the program loops.
  16.   tone(audioPin, pitch, 300); // Play the tone for 300ms.
  17.   delay(59700); // Delay figured for 1 minute - the 300ms.
  18.   pitch = (pitch + 10); // Increase the pitch.
  19.  
  20.   if(counter == 60){ // When the counter gets to 60 or 1 hour...
  21.     tone(audioPin, 1000, 300); // Play an extra tone.
  22.     pitch = 300; // Reset pitch.
  23.     counter = 0; // Reset counter.
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement