Example #1
0
void speaknum(char c)  //not using this one
{
  uint8_t i=0;
  
  // copy flash string for 'period' to filename
  strcpy_P(filename, PSTR("P.WAV"));
  
  if ('0' <= c && c <= '9') {
    // digit - change 'P' to digit
    filename[0] = c;
    i = 1;
  } 
  else if (c != '.') {
    // error if not period
    return;
  }
  playcomplete(filename);
}
Example #2
0
void loop() { 
   uint8_t i, r;
   char c, name[15];


   card.reset_dir();
   // scroll through the files in the directory
   for (i=0; i<tracknum+1; i++) {
     r = card.get_next_name_in_dir(name);
     if (!r) {
       // ran out of tracks! start over
       tracknum = 0;
       return;
     }
   }
   putstring("\n\rPlaying "); Serial.print(name);
   // reset the directory so we can find the file
   card.reset_dir();
   playcomplete(name);
   tracknum++;
}
Example #3
0
void loop() {

  /// ******** need to see if the alcohol sensor is ready / resetted *****
  AlcoholSensorValue = analogRead(AlcoholSensorPin);    //get value of alcohol sensor
  delay(50); //not sure if we need this but keep for now
  Serial.print("Alcohol Sensor Value from Beginning of Loop: ");
  Serial.println(AlcoholSensorValue);
  
  int deleteme = baseline + baselineDifference;
  Serial.print("baseline + baselineDifferent= ");
  Serial.println(deleteme);
  
   if (AlcoholSensorValue < baseline + baselineDifference) {  //the baseline difference is here because the MQ-3 alcohol sensor takes awhile to reset back to the original baseline so you can use this to get close enough so you don't have to wait so long to take the next reading
     digitalWrite(readyLEDPin, HIGH);
     Serial.println("Alcohol Sensor Ready");
     ready = 1;
    } 
   else {
     digitalWrite(readyLEDPin,LOW); 
     ready = 0;
  }
  //**********************************************************************

  //************ Now check if the button was pushed **********************  
  currentButtonState = digitalRead(buttonPin);
  Serial.println("Current Switch State: " + currentButtonState);
  // compare the buttonState to its previous state
  if (initialButtonState != currentButtonState && ready == 3 && playingFlag == 0) { //if button switched and alcohol sensor ready and not already playing
      playingFlag = 1;
      buttonPushCounter++;
      Serial.println("Switch was changed and Breathalyzer started...");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter, DEC);
      
      //digitalWrite(waitLEDPin, HIGH);
      AlcoholSensorDynamicBaseline = analogRead(AlcoholSensorPin); //now lets get the baseline alcohol sensor value before the person blows
      Serial.print("alcohol sensor value before blowing, alcohol dynamic baseine: ");  
      Serial.println(analogRead(AlcoholSensorPin));      
      
      switch (mode) {
              case 0:   
              playcomplete("wait0.wav");              
              break;
              case 1:     
              playcomplete("wait1.wav");      
              break;
              case 2:     
              playcomplete("wait2.wav"); 
              break;
              case 3:    
              playcomplete("wait3.wav"); 
              break;
          }    	
      delay(2000);     
      //digitalWrite(waitLEDPin, LOW);
      //digitalWrite(blowLEDPin, HIGH);
      switch (mode) {
              case 0:   
              playcomplete("blow0.wav");              
              break;
              case 1:     
              playcomplete("blow1.wav");      
              break;
              case 2:     
              playcomplete("blow2.wav"); 
              break;
              case 3:    
              playcomplete("blow3.wav"); 
              break;
          }    	
      delay(blowTime);     //default blow time is 5 seconds
      //digitalWrite(blowLEDPin, LOW);
      AlcoholSensorValue = analogRead(AlcoholSensorPin);   //now lets get the baseline alcohol sensor value after the person blows
      Serial.print("alcohol sensor value after blowing: ");   
      Serial.println(analogRead(AlcoholSensorPin));   
      
      if (AlcoholSensorValue < AlcoholSensorDynamicBaseline + level1) {  //if the baseline + the level1 threshold is less, then no alcohol
      	 digitalWrite(level0LEDPin, HIGH); //turns the pin off later   
            switch (mode) {
                case 0:    // your hand is on the sensor
                Serial.println("princess mode 0 no alcohol");    
                playcomplete("nothing0.wav");              
                break;
                case 1:    // your hand is close to the sensor
                Serial.println("pirate mode 1 no alcohol");   
                playcomplete("nothing1.wav");      
                break;
                case 2:    // your hand is a few inches from the sensor
                Serial.println("pirate mode 2 no alcohol");    
                playcomplete("nothing2.wav"); 
                break;
                case 3:    // your hand is nowhere near the sensor
                Serial.println("insult mode 3 no alcohol");   
                playcomplete("nothing3.wav"); 
                break;
            }    	
      }
      
       if (AlcoholSensorValue > AlcoholSensorDynamicBaseline + level1 && AlcoholSensorValue < AlcoholSensorDynamicBaseline + level2) {
          digitalWrite(level1LEDPin, HIGH); //turns the pin off later     
           switch (mode) {
                case 0:    // your hand is on the sensor
                Serial.println("princess mode 0 few drinks");    
                playcomplete("few0.wav");              
                break;
                case 1:    // your hand is close to the sensor
                Serial.println("pirate mode 1 few drinks");   
                playcomplete("few1.wav");      
                break;
                case 2:    // your hand is a few inches from the sensor
                Serial.println("halloween mode 2 few drinks");    
                playcomplete("few2.wav"); 
                break;
                case 3:    // your hand is nowhere near the sensor
                Serial.println("insult mode 3 few drinks");   
                playcomplete("few3.wav"); 
                break;
            }    	 	
      }
      
       if (AlcoholSensorValue > AlcoholSensorDynamicBaseline + level2 && AlcoholSensorValue < AlcoholSensorDynamicBaseline + level3) {
          digitalWrite(level2LEDPin, HIGH); //turns the pin off later      	
           switch (mode) {
                case 0:    // your hand is on the sensor
                Serial.println("princess mode 0 buzzed");    
                playcomplete("buzzed0.wav");              
                break;
                case 1:    // your hand is close to the sensor
                Serial.println("pirate mode 1 buzzed");   
                playcomplete("buzzed1.wav");      
                break;
                case 2:    // your hand is a few inches from the sensor
                Serial.println("halloween mode 2 buzzed");    
                playcomplete("buzzed2.wav"); 
                break;
                case 3:    // your hand is nowhere near the sensor
                Serial.println("insult mode 3 buzzed");   
                playcomplete("buzzed3.wav"); 
                break;
            }    	 	
      }
      
      if (AlcoholSensorValue > AlcoholSensorDynamicBaseline + level3) {
          digitalWrite(level3LEDPin, HIGH); //turns the pin off later      
           switch (mode) {
                case 0:    // your hand is on the sensor
                Serial.println("princess mode 0 drunk");    
                playcomplete("drunk0.wav");              
                break;
                case 1:    // your hand is close to the sensor
                Serial.println("pirate mode 1 drunk");   
                playcomplete("drunk1.wav");      
                break;
                case 2:    // your hand is a few inches from the sensor
                Serial.println("halloween mode 2 drunk");    
                playcomplete("drunk2.wav"); 
                break;
                case 3:    // your hand is nowhere near the sensor
                Serial.println("insult mode 3 drunk");   
                playcomplete("drunk3.wav"); 
                break;
            }    	 		
      }
      
    delay(LEDonTime);  //how long to leave the LEDs on before turning them off, default 5s    
    digitalWrite(level0LEDPin, LOW);    
    digitalWrite(level1LEDPin, LOW);    
    digitalWrite(level2LEDPin, LOW);   
    digitalWrite(level3LEDPin, LOW);        
    
    initialButtonState = currentButtonState;  //set this for the next button change
    playingFlag = 0;                          //now we're done so set this so the breahtalyzer can go again
  } //**************************************************end this if statement
  
  //************ now let's check if the pot has changed  
  currentPot = analogRead(PotPin);  
  changePot = abs(currentPot - initialPot); //see if the char select knob has been turned far enough
  Serial.print("Absolute pot value change is: "); //remove this later, just for debugging
  Serial.println(changePot); //remove this later, just for debugging
  delay(5000);
  
  if (changePot > 75) {        // this means the pot knob was turned
    initialPot = currentPot;   //now reset the baseline pot value
    delay (500);
    
    range = map(analogRead(PotPin), 0, 1023, 0, 3);  //split into 4
  
    switch (range) {
    case 0:    
      if (mode !=0) {                  //don't want to change to the same mode we were already on
        //play the char select sound
        mode = 0;
        Serial.println("princess mode change 0");
        playcomplete("mode0.wav"); 
      }  
      break;
    case 1:    
      if (mode !=1) {                  //don't want to change to the same mode we were already on
        //play the char select sound
        mode = 1;
        Serial.println("pirate mode change 1");
        playcomplete("mode1.wav"); 
      }  
      break;
    case 2:    
      if (mode !=2) {                  //don't want to change to the same mode we were already on
        //play the char select sound
        mode = 2;
        Serial.println("halloween mode change 2");
        playcomplete("mode2.wav"); 
      }  
      break;
    case 3:    
      if (mode !=3) {                  //don't want to change to the same mode we were already on
        //play the char select sound
        mode = 3;
        Serial.println("insult mode change 3");
        playcomplete("mode3.wav"); 
      }  
      break;
    }   //end case statement    
  } //******************************** end pot check ******************************* 
  
  
  
  
} //end loop