Skip to content

Commit

Permalink
Can send command to test ringing via serial
Browse files Browse the repository at this point in the history
Just send a T char to initiate testing the servo/doorbell
  • Loading branch information
lilspikey committed Oct 23, 2010
1 parent 08b07be commit 96dbd0a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions doorbell.pde
Expand Up @@ -17,6 +17,7 @@
#define DOORBELL_BACKWARD_ANGLE 90
#define DOORBELL_FORWARD_ANGLE 180


Servo servo;
int state;
unsigned long prev_millis;
Expand All @@ -25,6 +26,7 @@ unsigned int start_count;
unsigned int ring_count;
unsigned int finish_count;


void next_state(int nstate, unsigned int nduration=0) {
state = nstate;
prev_millis = millis();
Expand All @@ -36,6 +38,14 @@ void same_state() {
duration = 100;
}

void ring_bell() {
// ensure servo attached again
servo.attach(SERVO_PIN);
ring_count = 3;
Serial.println("DING DONG");
next_state(STATE_BELL_FORWARD);
}

void setup() {
Serial.begin(9600);
servo.attach(SERVO_PIN);
Expand All @@ -47,7 +57,12 @@ void setup() {

void loop() {
if ( Serial.available() ) {
// TODO handle serial data
char c = Serial.read();

// run command
if ( c == 'T' ) {
ring_bell();
}
}

if ( (millis() - prev_millis) > duration ) {
Expand All @@ -63,11 +78,7 @@ void loop() {
if ( v <= DOORBELL_THRESHOLD ) {
start_count++;
if ( start_count > 2 ) {
// ensure servo attached again
servo.attach(SERVO_PIN);
ring_count = 3;
Serial.println("DING DONG");
next_state(STATE_BELL_FORWARD);
ring_bell();
}
else {
same_state();
Expand Down

0 comments on commit 96dbd0a

Please sign in to comment.