Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int ledPin[2] = {5,6};
- const int button1pin = 2;
- const int button2pin = 3;
- const int numChoices = 4;
- int choices[numChoices] = {0, 1, 1, 0};
- int currentChoice = 0;
- bool isRecording = false;
- bool 1hasBeenPressed = false;
- bool 2hasBeenPressed = false;
- int buttonDebounce(int buttonPin) {
- int oldState;
- int currentState;
- oldState = digitalRead(buttonPin);
- delay(50);
- if (oldState == digitalRead(buttonPin));
- {
- currentState = digitalRead(buttonPin);
- }
- return currentState;
- }
- void record() {
- Serial.println("record");
- currentChoice = 0;
- while(currentChoice < numChoices)
- {
- if(buttonDebounce(button2pin) == HIGH && 1hasBeenPressed == false)
- {
- 1hasBeenPressed = true;
- addChoice(1);
- }
- if(buttonDebounce(button1pin) == HIGH && 2hasBeenPressed == false)
- {
- 2hasBeenPressed = true;
- addChoice(0);
- }
- if(digitalRead(button1pin == LOW)){
- if(buttonDebounce(button1pin) == LOW)
- {
- 1hasBeenPressed = false;
- }
- }
- if(digitalRead(button2pin == LOW)){
- if(buttonDebounce(button1pin) == LOW)
- {
- 2hasBeenPressed = false;
- }
- }
- }
- if (currentChoice >= numChoices)
- {
- currentChoice = 0;
- }
- }
- void addChoice(int buttonNum) {
- choices[currentChoice] = buttonNum;
- currentChoice += 1;
- Serial.println(currentChoice);
- Serial.println(buttonNum);
- }
- void play() {
- Serial.println("play");
- currentChoice = 0;
- while(currentChoice < 4)
- {
- Serial.print("led");
- analogWrite(ledPin[choices[currentChoice]], 50);
- delay(1000);
- analogWrite(ledPin[choices[currentChoice]], 0);
- delay(500);
- currentChoice += 1;
- }
- if (currentChoice >= 4)
- {
- currentChoice = 0;
- }
- }
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(button1pin, INPUT);
- pinMode(button2pin, INPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- //Serial.println("enter loop");
- if(digitalRead(button1pin == LOW)){
- if(buttonDebounce(button1pin) == LOW)
- {
- 1hasBeenPressed = false;
- }
- }
- if(digitalRead(button2pin == LOW)){
- if(buttonDebounce(button1pin) == LOW)
- {
- 2hasBeenPressed = false;
- }
- }
- if(digitalRead(button1pin) == HIGH && 1hasBeenPressed == false)
- {
- record();
- }
- if(digitalRead(button2pin) == HIGH && 2hasBeenPressed == false)
- {
- play();
- }
- //Serial.println("end loop");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement