Sunday, December 1, 2013

Code Catchup (LED Array, Sound and Fan)

Below is the code uploaded to our secondary board, which activates the sound and lights upon receiving a signal from the primary board. The potentiometer controlled fan code is integrated as well.

The current issue with this code is that we cannot get the alarm loop to continue after the primary board sends the initial signal. The goal is that the secondary board does nothing but spend its time constantly checking for a signal from the primary board. At 8:00:00, the primary board sends a single signal to the secondary board, activating an alarm loop that continues even after the signal ceases to be sent. That way, the alarm will continue until the secondary board is reset and begins waiting for 8:00:00 again. This way, the timer is never interrupted and can continue keeping time.


const byte POTENTIOMETER = 0;  // Plugged into A0
const byte CONTROL = 13;  // pin #
int reading;
int value;
int MakeSound=0;

int ledArray[] = {1,2,3,4,5};  //LED Array
int rate = 50;
int pause = 1;

void setup() {
  pinMode(CONTROL, OUTPUT);
  pinMode(11,OUTPUT);
 
  beep(50);
  beep(50);
  beep(50);
  delay(1000);
 
  pinMode(8,INPUT);
 
 
  for (int i=0; i<5; i++){  //LED Array
    pinMode(ledArray[i], OUTPUT);
 
}
}
void loop() {
  MakeSound=digitalRead(8);
   if (MakeSound==HIGH)
   {
     {
       beep(200);
     }
  for (int i=0; i<5; i++){
    digitalWrite(ledArray[i], HIGH);
    delay(rate);
    digitalWrite(ledArray[i], LOW);
    if (i == 4) delay(pause*rate);
    else delay(rate);
  }
   for (int j=1; j<4; j++){
    int k = 4-j;
    digitalWrite(ledArray[k], HIGH);
    delay(rate);
    digitalWrite(ledArray[k], LOW);
    delay(rate);
  }
}

  reading = analogRead(POTENTIOMETER);
  value = map(reading, 0, 1024, 0, 255);  
  analogWrite(CONTROL, value);
} // end loop


void beep(unsigned char delayms){
  analogWrite(11, 20);      // Almost any value can be used except 0 and 255
                           // experiment to get the best tone
  delay(delayms);          // wait for a delayms ms
  analogWrite(11, 0);       // 0 turns it off
  delay(delayms);          // wait for a delayms ms  
}

No comments:

Post a Comment