Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cannikin committed Apr 22, 2011
0 parents commit d1a7c2e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
41 changes: 41 additions & 0 deletions button/button.pde
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);
}
}

41 changes: 41 additions & 0 deletions speakers/speakers.pde
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);
}

}

0 comments on commit d1a7c2e

Please sign in to comment.