-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d1a7c2e
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Code for the big red button | ||
// | ||
// When sending a signal to the button to tell it to be on or off, | ||
// the byte 'N' means oN and byte 'F' means ofF. On and off correspond | ||
// to HIGH and LOW on pin 13 which is the LED in the button. | ||
|
||
#define led 13 | ||
#define button 2 | ||
|
||
int led_state = LOW; | ||
|
||
void setup() { | ||
pinMode(led, OUTPUT); | ||
pinMode(button, INPUT); | ||
digitalWrite(led, led_state); | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() { | ||
|
||
int button_state = digitalRead(button); | ||
|
||
if (button_state == HIGH) { | ||
delay(100); | ||
Serial.print('P'); | ||
} | ||
|
||
// if the speaker has sent a byte back | ||
if (Serial.available()) { | ||
byte state = Serial.read(); | ||
if (state == 'N') { | ||
led_state = HIGH; | ||
} else if (state == 'F') { | ||
led_state = LOW; | ||
} | ||
|
||
// update the state of the LED | ||
digitalWrite(13, led_state); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Code for the speaker controller | ||
|
||
// All the buttons do is send the byte 'P' to mean that the button has been pressed | ||
// This module decides how to respond to that P by either turning the relay on or off | ||
|
||
#define relay 2 | ||
#define led 13 | ||
|
||
int speaker_state = LOW; | ||
|
||
void setup() { | ||
pinMode(relay, OUTPUT); | ||
pinMode(led, OUTPUT); | ||
digitalWrite(relay, speaker_state); | ||
digitalWrite(led, speaker_state); | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() { | ||
|
||
if (Serial.available()) { | ||
|
||
byte signal = Serial.read(); | ||
|
||
if (signal == 'P') { | ||
if (speaker_state == LOW) { | ||
speaker_state = HIGH; | ||
Serial.print('N'); | ||
} else { | ||
speaker_state = LOW; | ||
Serial.print('F'); | ||
} | ||
} | ||
|
||
digitalWrite(relay, speaker_state); | ||
digitalWrite(led, speaker_state); | ||
|
||
delay(100); | ||
} | ||
|
||
} |