Danger Shield Test Components

Here a components test for your Danger Shield.
I hope you could enjoy this :slight_smile:

/* 
29/12/2010
project: Sketch for Danger Shield Check
by: dejan21
note: no libraries need
*/

// VAR
int val = 0;
int state = 0;
int state3 = 0;
int x = 0;
int i = 0;
int statenew = 0;
int stateold = 0;
const byte numeri[10] = {
  B00111111, //0
  B00000110, //1
  B01011011, //2
  B01001111, //3
  B01100110, //4
  B01101101, //5 
  B01111101, //6
  B00000111, //7
  B01111111, //8
  B01101111  //9
};
//PIN DIGITALI BOTTONI
#define BUTTON1_PIN 2
#define BUTTON2_PIN 7
#define BUTTON3_PIN 4
//SLIDERS ANALOGICHE
#define SLIDER1_PIN 0
#define SLIDER2_PIN 1
#define SLIDER3_PIN 2
//SENSOR
#define LIGHT_SENSOR_PIN 3
#define TEMP_SENSOR_PIN 4
#define KNOCK_SENSOR_PIN 5
//LED & BUZZER
#define LED1_PIN 6
#define LED2_PIN 5
#define BUZZER_PIN 3
#define SLIDER1_LED_PIN 11
#define SLIDER2_LED_PIN 10
#define SLIDER3_LED_PIN 9
//PIN
#define LATCH_PIN 8
#define CLOCK_PIN 12
#define DATA_PIN 13
//NUMBER TEST
#define TESTSLIDER 1
#define TESTBUZZER 2
#define TESTKNOCK  3
#define TESTSENSORETEMPERATURA  4
#define TESTSENSORELUMINOSITA 5
#define TESTBOTTONE3 6
#define TESTDISPLAY 7


void setup()
{
  Serial.begin(9600);
  digitalRead(BUTTON1_PIN);
  digitalRead(BUTTON3_PIN);
  digitalRead(BUTTON2_PIN);
  digitalWrite(LED1_PIN,HIGH);
  digitalWrite(LED2_PIN,HIGH);
  
  analogRead(SLIDER1_PIN);
  analogRead(SLIDER2_PIN);
  analogRead(SLIDER3_PIN);
  analogWrite(SLIDER1_LED_PIN,HIGH);
  analogWrite(SLIDER2_LED_PIN,HIGH);
  analogWrite(SLIDER3_LED_PIN,HIGH);
 
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED1_PIN, OUTPUT);
  pinMode(LED2_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN,OUTPUT);
  
  Serial.println("DANGER SHIELD CHECK COMPONENTS");
  Serial.println("PUSH BUTTON1 TO SELECT THE TEST");
  Serial.println("PUSH BUTTON2 TO START THE TEST SELECTED");
  Serial.println("PUSH RESET BUTTON TO RESTART THE CHECK");
  Serial.println("TEST 1 = SLIDERS ");
  Serial.println("TEST 2 = BUZZER ");
  Serial.println("TEST 3 = KNOCK SENSOR ");
  Serial.println("TEST 4 = TEMP SENSOR ");
  Serial.println("TEST 5 = LIGHT SENSOR ");
  Serial.println("TEST 6 = BUTTON3 ");
  Serial.println("TEST 7 = DISPLAY 7 SEGMENTS ");
  Serial.println("If the test is ok you'll read  TEST = OK");  
  Serial.println(""); 
  Serial.println("loading test LED1 e LED2 ..."); 
  delay(2000);
  Serial.println("please wait...");
  delay(3000);
  Serial.println("Now leds blink");
  delay(1000);
  for (int contatore = 0; contatore < 15; contatore++) 
         {
          digitalWrite(LED1_PIN,HIGH);
          delay(100);
          digitalWrite(LED1_PIN,LOW);
          delay(100);
          digitalWrite(LED2_PIN,HIGH);
          delay(100);
          digitalWrite(LED2_PIN,LOW);
          delay(100);
          }
  Serial.println("If the leds blink the DANGER SHIELD is ready for the CHECK COMPONENTS");
  Serial.println("Push BUTTON1 to start selection TEST");
}


void loop()
{ 
  
  int stato1 = digitalRead(BUTTON1_PIN);
  if(stato1==1)
  {
    delay(1000);
    statenew ++;
    if (statenew > stateold)
    {
      byte j = numeri[statenew];
      digitalWrite(LATCH_PIN, LOW);
      shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, j);
      digitalWrite(LATCH_PIN, HIGH);
      Serial.println("");
      Serial.print("TEST "); 
      Serial.print(statenew);
      Serial.print(": Push BUTTON2 to start this TEST");
        
      stateold = statenew;
      if (statenew == 7)
      {
        statenew=0;
        stateold=0;
      } 
    }
  }

  int stato2 = digitalRead(BUTTON2_PIN);

  if(stato2==1)
  {
    delay(500);
    if (statenew == 0)
    { 
      statenew = 7;
    }
    Serial.println("");
    Serial.print("TEST ");
    Serial.println(statenew);
    Serial.println("please wait...");
    byte j = numeri[0];
      digitalWrite(LATCH_PIN, LOW);
      shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, j);
      digitalWrite(LATCH_PIN, HIGH);
    delay(2000);

    //TEST SLIDERS
    if(statenew == TESTSLIDER)
    {
      delay (1000);
      Serial.println("TEST SLIDERS: ");
      val = analogRead(SLIDER1_LED_PIN);
       Serial.println("TEST = OK if you can see analogic values & leds blink");
      Serial.print("slider1 = ");
      Serial.println(val);
      val = analogRead(SLIDER2_LED_PIN);
      Serial.print("slider2 = ");
      Serial.println(val);
      val = analogRead(SLIDER3_LED_PIN);
      Serial.print("slider3 = ");
      Serial.println(val);
       for (int contatore = 0; contatore < 15; contatore++) 
        {
          analogWrite(SLIDER1_LED_PIN,LOW);
          delay (100);
          analogWrite(SLIDER2_LED_PIN,LOW);
          delay(100);
          analogWrite(SLIDER3_LED_PIN,LOW);
          delay(100);
          analogWrite(SLIDER1_LED_PIN,HIGH);
          delay (100);
          analogWrite(SLIDER2_LED_PIN,HIGH);
          delay(100);
          analogWrite(SLIDER3_LED_PIN,HIGH);
          delay(100);
        }
     
    }



    //TEST BUZZER
    if(statenew == TESTBUZZER) 
    {
      Serial.println("TEST BUZZER");
      for(int x = 0; x < 5; x++)
      {
        digitalWrite(BUZZER_PIN, HIGH);
        delay(100);
        digitalWrite(BUZZER_PIN, LOW);
        delay(100);
      }
      Serial.println("TEST = OK if buzzer produces intermittence noise");
    }




    //TEST KNOCK
    if(statenew == TESTKNOCK) 
    {
      Serial.println("TEST KNOCK"); 
      val = analogRead(KNOCK_SENSOR_PIN);
      if(val > 10)
      delay(1550);
        {
        Serial.println("TEST = OK if LED1 blink");  
        digitalWrite(LED2_PIN,LOW);
        for (int contatore = 0; contatore < 30; contatore++) 
        {
          digitalWrite(LED1_PIN,HIGH);
          delay (100);
          digitalWrite(LED1_PIN,LOW);
          delay(100);
      
        }
        
      }
      
      
    }





    //TEST TEMP SENSOR
    if(statenew == TESTSENSORETEMPERATURA) 
    {
      Serial.println("TEST TEMP SENSOR"); 
      val = analogRead(TEMP_SENSOR_PIN);
      Serial.print("Temp value: ");
      Serial.println(val);
      Serial.println("TEST = OK if you have a temp value");
    }



    //TEST LIGHT SENSOR
    if(statenew == TESTSENSORELUMINOSITA) 
    {
      Serial.println("TEST LIGHT SENSOR");
      val = analogRead(LIGHT_SENSOR_PIN);
      Serial.print("Light value: ");
      Serial.println(val);
      Serial.println("TEST = OK if you have a light value'");
    }




    //TEST BUTTON3
    if(statenew == TESTBOTTONE3) 
    {  
      Serial.println("TEST BUTTON 3");
      Serial.println("Push & Hold BUTTON3 within 5 seconds");

      delay (5000);
      state3 = digitalRead(BUTTON3_PIN);
      if (state3 == 1)
      {
        Serial.println("TEST = OK if LED1 and LED2 blink");
        for (int contatore2 = 0; contatore2 < 10; contatore2++) 
        {
          digitalWrite(LED1_PIN,HIGH);
          delay (100);
          digitalWrite(LED2_PIN,HIGH);
          delay(100);  
          digitalWrite(LED1_PIN,LOW);
          delay (100);
          digitalWrite(LED2_PIN,LOW);
          delay(100);
        }
      }
      else
      {
        Serial.println("Button 3 not checked or pushed");

      }

    }



    //TEST DISPLAY 7 SEGMENTs
    if(statenew == TESTDISPLAY) 
    {
      i = 0;
      Serial.println("TEST DISPLAY");
      for (int i=10; i>-1; i--)
      {
        byte j = numeri[i];
        digitalWrite(LATCH_PIN, LOW);
        shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, j);
        digitalWrite(LATCH_PIN, HIGH);
        delay(500);
      }
      Serial.println("TEST = OK if countdown started");
    }

    statenew=0;
    stateold=0;

  }

}