waterlubber

The Singing Relay

Feb 5th, 2015
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. /* Created by waterlubber
  2.  _________  ________  ________    
  3. |\___   ___\\   ____\|\   __  \    
  4. \|___ \  \_\ \  \___|\ \  \|\  \  
  5.      \ \  \ \ \_____  \ \   _  _\  
  6.       \ \  \ \|____|\  \ \  \\  \|
  7.        \ \__\  ____\_\  \ \__\\ _\
  8.         \|__| |\_________\|__|\|__|
  9.               \|_________|        
  10.                                    
  11.                                  
  12.                                  
  13. The Singing Relay
  14.  
  15.  
  16. This is liscensed under GPL V3
  17. http://opensource.org/licenses/GPL-3.0
  18. I am not liable for any damages caused by this software. Use it at your own
  19. risk. It is provided AS IS without any guarentees.
  20. -----
  21. This uses the relay shield from seeedstudio. http://seeedstudio.com
  22. You may connect a buzzer's input +5V terminal to the pins configured
  23. below. It requires a serial connection.
  24.  
  25. Type in a number from 0-1000. 1000 being 500 Hz and 0 being 1 Hz.
  26. */
  27. int buzzer = 7; //Pre-Configured Pins
  28. int buzzer2 = 4;
  29. int value = 0;
  30.  
  31. void setup() {
  32.   Serial.begin(9600); //Serial Baud Rate 9600
  33.   pinMode(buzzer, OUTPUT);
  34.   pinMode(buzzer2, OUTPUT);
  35.  
  36. }
  37.  
  38. void loop() {
  39.   while (Serial.available() > 0) { //Checks for data in serial buffer
  40.     value = Serial.parseInt(); //Turns data into a number.
  41.     Serial.println(value); //Returns the data, for troubleshooting.
  42.   }
  43.   digitalWrite(buzzer, HIGH);
  44.   delay((1001 -value) / 30);
  45.   digitalWrite(buzzer2, HIGH);
  46.   delay(1001-value);
  47.   digitalWrite(buzzer, LOW);
  48.   delay((1001 - value) / 30);
  49.   digitalWrite(buzzer2, LOW);
  50.   delay(1001-value);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment