Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. const int ledPin = LED_BUILTIN;
  2. int ledState = LOW;
  3. unsigned long previuosTime = 0;
  4. const long interval = 1000;
  5.  
  6. const int ledOnePin = 12;
  7. const int ledTwoPin = 8;
  8. const int buttonOnePin = 2;
  9. int buttonOneState = 0; // variable for reading the pushbutton status
  10.  
  11. #include "pitches.h";
  12. const int buzzerPin = 7;
  13. const int buttonTwoPin = 4;
  14. const int ledThreePin = 10;
  15. int buttonTwoState = 0;
  16. int melody[] = {
  17.   NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
  18.   };
  19. int durations[] = {
  20.   4, 8, 8, 4, 4, 4, 4, 4 // 4 = quarter note, 8 = eighth note, etc.
  21.   };
  22.  
  23. void setup() {
  24.   Serial.begin(9600); // initialize serial communication at 9600 bits per second:
  25.   pinMode(ledPin, OUTPUT);
  26.   pinMode(buttonOnePin, INPUT);
  27.   pinMode(ledOnePin, OUTPUT);
  28.   pinMode(ledTwoPin, OUTPUT);
  29.   pinMode(buttonTwoPin, INPUT);
  30.   pinMode(ledThreePin, OUTPUT);
  31. }
  32.  
  33. void loop() {
  34.   // put your main code here, to run repeatedly:
  35.  
  36.   buttonOneState = digitalRead(buttonOnePin);
  37.  
  38.   if (buttonOneState == HIGH) {
  39.     digitalWrite(ledOnePin, buttonOneState);
  40.     digitalWrite(ledTwoPin, LOW);
  41.     Serial.println("ledOne ON +++");
  42.   } else {
  43.     digitalWrite(ledOnePin, buttonOneState);
  44.     digitalWrite(ledTwoPin, HIGH);
  45.     Serial.println("ledOne OFF ---");
  46.   }
  47.  
  48.  
  49.   buttonTwoState = digitalRead(buttonTwoPin);
  50.   digitalWrite(ledThreePin, buttonTwoState); // red light mother fucker
  51.  
  52.   if (buttonTwoState == HIGH){
  53.  
  54.     digitalWrite(ledTwoPin, LOW); // :)
  55.     digitalWrite(ledOnePin, LOW); // :)
  56.     for (int thisNote=0; thisNote<8; thisNote++){
  57.      
  58.       int noteDuration = 1000/durations[thisNote];
  59.  
  60.       tone(buzzerPin, melody[thisNote], noteDuration);
  61.  
  62.       int pauseBetweenNotes = noteDuration * 1.30;
  63.       delay(pauseBetweenNotes);
  64.      
  65.       noTone(buzzerPin);
  66.     }
  67.   }
  68.  
  69.   //end of regular code
  70.  
  71.   unsigned long currentTime = millis();
  72.  
  73.   if (currentTime - previuosTime >= interval){
  74.     previuosTime = currentTime;
  75.  
  76.     if (ledState == LOW) {
  77.       ledState = HIGH;
  78.       Serial.println("IIIIIIIIIIIIIIIIIIIII on IIIIIIIIIIIIIIIIIIIII");
  79.     } else {
  80.       ledState = LOW;
  81.     }
  82.  
  83.     digitalWrite(ledPin, ledState);
  84.   }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement