Exemple #1
0
// call set up function to set up pins:
void setup(void) { // Start up instructions:
    freq[0].begin(11); // Initialize our first tone generator
    freq[1].begin(12); // Initialize our second tone generator
    keypad.setHoldTime(1500); // hold for two seconds to change state to HOLD
    pinMode(10, INPUT); // 2600 button
    pinMode(13, OUTPUT); // LED for recording
    keypad.addEventListener(procButton);
    notify(); // boot successful
    Serial.begin(9600);
}
void loop() {
    char key = keypad.getKey();

    if (key != NO_KEY) {
        Serial.println(key);
    }
}
void keyPresets() {
  char key = kpd.getKey();
 
  if(key=='1'){
    turnUpServo();
    seconds = 5;   
    timer();
    mode = 0;
  }
  if(key=='2'){
    turnUpServo();
    seconds = 15;    
    timer(); 
    mode = 1; 
  }
  if(key=='3'){
    turnUpServo();
    seconds = 35;      
    timer(); 
    mode = 1;
  }
  if(key=='0'){
    if(mode == 0){
      phTurnOff = 0;
      mode = 1;
      Serial.println("AUTO mode activated");
    }
    else if(mode == 1){
      mode = 0;
      myservo.write(180);
      Serial.println("MANUAL mode activated");
    }
  }
}
Exemple #4
0
// our main() function:
void loop(void) { // Here we just get the button, pressed or held, and 2600 switch
    char button = keypad.getKey(); // check for button press
    if(digitalRead(10)==HIGH) { // play 2600Hz if top button pressed
        super(); // supervisory signalling
    }
    return; // end main()
}
Exemple #5
0
// --- setup ---
void setup()
{
	pinMode(alarmPin, OUTPUT);
	pinMode(pirPin, INPUT);
// 	pinMode(relayPin, OUTPUT);
  kpd.addEventListener(kpdEvent); //keypad event listener
  Serial.begin(9600); // serial debug
  slcd.begin();
  set_lcd("bonjour", "");
  delay(3000);
  set_lcd("demarre", "");
}
Exemple #6
0
int main(void) {
	const byte rows = 4; //four rows
	const byte cols = 3; //three columns
	char keys[rows][cols] = {
	  {'1','2','3'},
	  {'4','5','6'},
	  {'7','8','9'},
	  {'*','0','#'}
	};
	byte	rowPins[rows] = {J1_9, J1_8, J1_7, J1_6};	//connect to the row pinouts of the keypad
	byte	colPins[cols] = {J1_5, J1_4, J1_3};			//connect to the column pinouts of the keypad
	Serial	pc(PA_1, PA_0);
	Keypad	keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
	pc.baud(19200);
	pc.println("InputNumber");
	wait_ms(500);
	while (1) {
		char c = keypad.getKey();
		if (c)
			pc.write(c);
	}
}
Exemple #7
0
void task_keypad(void* p){
	
	/*KeyPad code*/
	while(1)
	{
		char key = keypad.getKey();

		//print out the key that is pressed
		if (key != NO_KEY){
			dprintf("%c",key);
			data[ID_DATA_KEYPAD] = (int) key;
			
		}
		//Serial.println("---------------------");
		vTaskDelay(taskDelay);
	}
	/*KeyPad Code*/
	
}
void loop(){
	if (delayInactif.check()) {
		stateProgram = NORMAL;
		clearBuffers();
		Serial.println("raz");
	}
	char key = keypad.getKey();
	if (key != NO_KEY){
		delayInactif.reset();
		delay(100); 
		switch (key){
			case 'A': 
			case 'B': 
			case 'C':
			case 'D':
				break; 
			case '#': 
				// reset pwd
				if (stateProgram == NORMAL) {
					chaineReset(&pwd_buffer);
				}
				else { modifyPwd(key); }
				break;
			case '*': 
				// check pwd
				if (stateProgram == NORMAL) {
					checkPwd();
					chaineReset(&pwd_buffer);
				}
				else { modifyPwd(key); }
				break;
			default: 
				//append to buffer
				if (stateProgram == NORMAL) {
					chaineAppend(key, &pwd_buffer);
					chainePrint(pwd_buffer);
				}
				else { modifyPwd(key); }
			// end of switch
		}
	}
}
Exemple #9
0
int main(void)
{
	init();

	oBus.SetEventReceive(EventBusRx);
	oBus.SetEventRequest(EventBusTx);
    
	for (;;)
	{
		if(nKey < 20)
		{
			char key = oKey.getKey();
			if (key != NO_KEY)
			{
				ccKey[nKey] = key;
				nKey++;
			}
		}	
	}
        
	return 0;
}
Exemple #10
0
void kpdEvent (KeypadEvent Key)
{
  switch (kpd.getState())
  {
    case PRESSED :
      Serial.println(Key); // mj
      switch (Key)
      {
        // appui sur '*' -> vérification de la saisie en cours
        case '*' : 
          checkPassword(); 
        break;
        // appui sur '#' -> réinitialisation de la saisie en cours
        case '#' : 
          pwd.reset();
          clear_lcd_pin(); 
        break;
        // sinon on ajoute le chiffre à la combinaison
        default  : pwd.append(Key); break;
      }
    set_lcd_pin();
    default : break;
  }
}
Exemple #11
0
//===============================================================================
void program() {

    switch(progState) {

    case 0:

        lcd.setCursor(0,0);
        lcd.print("Use keypad ?    ");
        lcd.setCursor(0,1);
        lcd.print("*-Yes       #-No");
        programed = false;

        but = keypadA.getKey();

        if (but == '#') {
            keypadBool = false;
            progState = 1;
            but = NO_KEY;
        }
        else if (but == '*') {
            keypadBool = true;
            progState = 1;
            but = NO_KEY;
        }

        break;

    //----------------------------------------------------------------------
    case 1:
        lcd.setCursor(0,0);
        lcd.print("Use key ?       ");
        lcd.setCursor(0,1);
        lcd.print("*-Yes       #-No");

        but = keypadA.getKey();

        if (but == '#') {
            keyBool = false;
            progState = 2;
            but = NO_KEY;
        }
        else if (but == '*') {
            keyBool = true;
            progState = 2;
            but = NO_KEY;
        }
        break;

    //----------------------------------------------------------------------
    case 2:
        lcd.setCursor(0,0);
        lcd.print("Use Wires ?     ");
        lcd.setCursor(0,1);
        lcd.print("*-Yes       #-No");

        but = keypadA.getKey();

        if (but == '#') {
            wireBool = false;
            progState = 3;
            but = NO_KEY;
        }
        else if (but == '*') {
            wireBool = true;
            progState = 3;
            but = NO_KEY;
        }
        break;

    //----------------------------------------------------------------------
    case 3:
        lcd.setCursor(0,0);
        lcd.print("Use Timer ?     ");
        lcd.setCursor(0,1);
        lcd.print("*-Yes       #-No");

        but = keypadA.getKey();

        if (but == '#') {
            timerBool = false;
            progState = 4;
            but = NO_KEY;
        }
        else if (but == '*') {
            timerBool = true;
            progState = 4;
            but = NO_KEY;
        }
        break;

    //----------------------------------------------------------------------
    case 4:
        lcd.setCursor(0,0);
        lcd.print("KP-");
        lcd.print(keypadBool);
        lcd.print("Ky-");
        lcd.print(keyBool);
        lcd.print("W-");
        lcd.print(wireBool);
        lcd.print("T-");
        lcd.print(timerBool);
        lcd.setCursor(0,1);
        lcd.print("*-Yes       #-No");

        but = keypadA.getKey();

        if (but == '#') {
            progState = 5;
            but = NO_KEY;
        }
        else if (but == '*') {
            progState = 5;
            statea = 1;
            i = 0;
            but = NO_KEY;
        }
        break;

    //----------------------------------------------------------------------
    case 5:

        switch(mode) {

        case 1:
            if(keypadBool == true) {
                switch (statea) {
                case 1:
                    lcd.setCursor(0, 0);
                    lcd.print("Enter 4Digit pin");
                    lcd.setCursor(0, 1);
                    lcd.print(code[0]);
                    lcd.print(code[1]);
                    lcd.print(code[2]);
                    lcd.print(code[3]);
                    lcd.print("           ");

                    but = keypadA.getKey();

                    if((but != NO_KEY) && (i < 4)) {
                        code[i] = but;
                        i++;
                        but = '-';
                    }

                    if(i >= 4) {
                        statea = 2;
                        i = 0;
                    }
                    break;

                case 2:
                    lcd.setCursor(0, 0);
                    lcd.print("# of attempts   ");
                    lcd.setCursor(0, 1);
                    lcd.print(time[0]);
                    lcd.print(time[1]);
                    lcd.print(time[2]);
                    lcd.print(time[3]);

                    but = keypadA.getKey();

                    if((i >= 4) || (but == '#')) {
                        attempts = atoi(time);
                        if(attempts == 0)
                            attem = false;
                        else
                            attem = true;
                        statea = 3;
                        but = NO_KEY;
                    }

                    if((but != NO_KEY) && (i < 4)) {
                        time[i] = but;
                        i++;
                        but = '-';
                    }
                    break;

                case 3:
                    lcd.setCursor(0, 0);
                    lcd.print("C -");
                    lcd.print(code[0]);
                    lcd.print(code[1]);
                    lcd.print(code[2]);
                    lcd.print(code[3]);
                    lcd.print(" A -");
                    lcd.print(attempts);
                    lcd.setCursor(0, 1);
                    lcd.print("*-Yes       #-No");

                    but = keypadA.getKey();

                    if (but == '#') {
                        statea = 1;
                        i = 0;
                        code[0] = '-';
                        code[1] = '-';
                        code[2] = '-';
                        code[3] = '-';
                        but = NO_KEY;
                    }
                    else if (but == '*') {
                        statea = 5;
                        mode = 2;
                        attemCount = attempts;
                        but = NO_KEY;
                    }
                    break;
                }
            }
            else
                mode = 2;
            break;

        case 2:
            if(keyBool == true) {
                if(digitalRead(largeKey) == HIGH)
                    lKey = false;
                else
                    lKey = true;
            }
            statea = 1;
            mode = 3;
            break;

        case 3:
            if(wireBool == true) {
                switch(statea) {
                case 1:
                    lcd.setCursor(0, 0);
                    lcd.print("Sel disarm wire");
                    lcd.setCursor(0, 1);
                    lcd.print("                ");

                    but = keypadA.getKey();

                    if(but == '1') {
                        safeWire = 1;
                        but = '-';
                        statea = 2;
                    }
                    else if(but == '2') {
                        safeWire = 2;
                        but = '-';
                        statea = 2;
                    }
                    else if(but == '3') {
                        safeWire = 3;
                        but = '-';
                        statea = 2;
                    }
                    else if(but == '4') {
                        safeWire = 4;
                        but = '-';
                        statea = 2;
                    }
                    break;

                case 2:
                    lcd.setCursor(0, 0);
                    lcd.print("Disarm wire - ");
                    lcd.print(safeWire);
                    lcd.setCursor(0, 1);
                    lcd.print("*-Yes       #-No");

                    but = keypadA.getKey();

                    if (but == '#') {
                        statea = 1;
                        safeWire = 0;
                        but = NO_KEY;
                    }
                    else if (but == '*') {
                        statea = 5;
                        progState = 6;
                        but = NO_KEY;
                    }
                    break;
                }
            }
            else {
                progState = 6;
            }
            break;
        }
        break;

    //----------------------------------------------------------------------
    case 6:
        lcd.setCursor(0, 0);
        lcd.print("Remove prog key");
        lcd.setCursor(0, 1);
        lcd.print("     to arm    ");

        programed = true;
        statea = 1;
        i = 0;
        wireDis = false;
        keyDis = false;
        keypadDis = false;
        bang = false;
        break;
    }
}
Exemple #12
0
// --- loop ---
void loop(){
	char Key = kpd.getKey();
	switch (alarmState) {
		// off - system idle
	  case off:
			set_sirene(false);
			goto_on_if_password();
    	break;

		// wait_on - delay before on (delai de sortie maison)
	  case wait_on:
			set_sirene(false);
			goto_off_if_password();
			if(wait_on_timer.check() == 1){
				set_lcd("alarm on", "");
				next_alarmState = on;
			}
    	break;

		// on - system is running
	  case on:
			set_sirene(false);
			if(get_sensors()) {
				next_alarmState = detection;
				set_lcd("detection", "");
			}
			goto_off_if_password();
    	break;

		// detection - movement detected
	  case detection:
			set_sirene(false);
			send_sms();
			goto_off_if_password();
			before_sirene_timer.reset();
			next_alarmState = 	before_sirene;
	    break;
	
		// before_sirene - delay before sirene (delai d'entrée dans maison) 
	  case before_sirene:
			set_sirene(false);
			if(before_sirene_timer.check() == 1){
				ring_sirene_timer.reset();
				next_alarmState = ring_sirene;
				set_lcd("sirene", "");
			}
			goto_off_if_password();
	    break;

		// sirene - sirene is crying
	  case ring_sirene:
			set_sirene(true);
			goto_off_if_password();
			if(ring_sirene_timer.check() == 1){
				wait_on_timer.reset();
				next_alarmState = wait_on;
				set_lcd("wait_on", "");			
			}
	    break;
	}
	alarmState = next_alarmState;
}
Exemple #13
0
void task_poll_sensor(void* p){

	while(1){
		//unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
		//unsigned int uS2 = sonar2.ping();
		/* Serial.print("Sonar 1: ");
		Serial.print(sonar.convert_cm(uS)); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
		Serial.println("cm");
  
		Serial.print("Sonar 2: ");
		Serial.print(sonar2.convert_cm(uS2));
		Serial.println("cm");*/
 
 
	//	dprintf("%d",(int)sonar.convert_cm(uS));
	//	vTaskDelay(1000);
		// dprintf("%d",(int)sonar.convert_cm(uS2));

		/* if(sonar.convert_cm(uS)<50){
		digitalWrite(MOTOR, HIGH);   // sets the LED on
		delay(100);                  // waits for a second
		//digitalWrite(MOTOR, LOW);    // sets the LED off
		//delay(1000);                  // waits for a second
		}else{
		digitalWrite(MOTOR, LOW);
		delay(100);
		}

		*/
		
		/*	 digitalWrite(TRIGGER_PIN, LOW);
			 delayMicroseconds(2);

			 digitalWrite(TRIGGER_PIN, HIGH);
			 delayMicroseconds(10);
			 
			 digitalWrite(TRIGGER_PIN, LOW);
			 pinMode(ECHO_PIN,INPUT);
			 duration = pulseIn(ECHO_PIN, HIGH,100000);
			 
			 //Calculate the distance (in cm) based on the speed of sound.
			 distance = duration/58.2;
		//	dprintf("%d 1", (int)distance);
			
			 digitalWrite(TRIGGER_PIN2, LOW);
			 delayMicroseconds(2);

			 digitalWrite(TRIGGER_PIN2, HIGH);
			 delayMicroseconds(10);
			 
			 digitalWrite(TRIGGER_PIN2, LOW);
			 pinMode(ECHO_PIN2,INPUT);
			 duration = pulseIn(ECHO_PIN2, HIGH,100000);
			 
			 //Calculate the distance (in cm) based on the speed of sound.
			 distance = duration/58.2;
		//	 dprintf("%d 2", (int)distance);
			 
			 
			 
			  digitalWrite(TRIGGER_PIN3, LOW);
			  delayMicroseconds(2);

			  digitalWrite(TRIGGER_PIN3, HIGH);
			  delayMicroseconds(10);
			  
			  digitalWrite(TRIGGER_PIN3, LOW);
			  pinMode(ECHO_PIN3,INPUT);
			  duration = pulseIn(ECHO_PIN3, HIGH,100000);
			  
			  //Calculate the distance (in cm) based on the speed of sound.
			  distance = duration/58.2;
			//  dprintf("%d 3", (int)distance);
			  
			  
			  
			   digitalWrite(TRIGGER_PIN4, LOW);
			   delayMicroseconds(2);

			   digitalWrite(TRIGGER_PIN4, HIGH);
			   delayMicroseconds(10);
			   
			   digitalWrite(TRIGGER_PIN4, LOW);
			   pinMode(ECHO_PIN4,INPUT);
			   duration = pulseIn(ECHO_PIN4, HIGH,100000);
			   
			   //Calculate the distance (in cm) based on the speed of sound.
			   distance = duration/58.2;
			//   dprintf("%d 4", (int)distance);
			   
			   
			    digitalWrite(TRIGGER_PIN5, LOW);
			    delayMicroseconds(2);

			    digitalWrite(TRIGGER_PIN5, HIGH);
			    delayMicroseconds(10);
			    
			    digitalWrite(TRIGGER_PIN5, LOW);
			    pinMode(ECHO_PIN5,INPUT);
			    duration = pulseIn(ECHO_PIN5, HIGH,100000);
			    
			    //Calculate the distance (in cm) based on the speed of sound.
			    distance = duration/58.2;
		//	    dprintf("%d 5", (int)distance);
			
			

			
		//Calculate the distance (in cm) based on the speed of sound.
		/*distance = duration/58.2;*/
		float distance1,distance2,distance3,distance4,distance5;
		distance1 = sonar_read(TRIGGER_PIN,ECHO_PIN);
		distance2= sonar_read(TRIGGER_PIN2,ECHO_PIN2);
		distance3 = sonar_read(TRIGGER_PIN3,ECHO_PIN3);
		distance4 = sonar_read(TRIGGER_PIN4,ECHO_PIN4);	
		distance5 = sonar_read(TRIGGER_PIN5,ECHO_PIN5);
		dprintf("%d %d %d %d %d",(int)distance1,(int)distance2,(int)distance3,(int)distance4,(int)distance5);
		
		/*dprintf("%d", (int) sonar_read(TRIGGER_PIN,ECHO_PIN));
		dprintf("%d", (int) sonar_read(TRIGGER_PIN2,ECHO_PIN2));
		dprintf("%d", (int) sonar_read(TRIGGER_PIN3,ECHO_PIN3));
		dprintf("%d", (int) sonar_read(TRIGGER_PIN4,ECHO_PIN4));
		dprintf("%d", (int) sonar_read(TRIGGER_PIN5,ECHO_PIN5));*/
		
		
 /*sonar final code
 digitalWrite(TRIGGER_PIN, LOW);
		  delayMicroseconds(2);

		  digitalWrite(TRIGGER_PIN, HIGH);
		  delayMicroseconds(10);
		  
		  digitalWrite(TRIGGER_PIN, LOW);
		  pinMode(ECHO_PIN,INPUT);
		  duration = pulseIn(ECHO_PIN, HIGH,100000);
		  
		  //Calculate the distance (in cm) based on the speed of sound.
		  distance = duration/58.2;
		  
		  */
		  
		  /*
		 pinMode(ECHO_PIN,INPUT);
		 digitalWrite(TRIGGER_PIN,HIGH);
		 delayMicroseconds(1000);
		 digitalWrite(TRIGGER_PIN,LOW);
		 duration = pulseIn(ECHO_PIN,HIGH);
		 distance = (duration/2)/29.1;*/
		/*  if(distance>10 && distance < 60){
			  digitalWrite(MOTOR, HIGH);   // sets the LED on
			  //  delay(100);                  // waits for a second
			  //digitalWrite(MOTOR, LOW);    // sets the LED off
			  //delay(1000);                  // waits for a second
			  }else{
			  digitalWrite(MOTOR, LOW);
			  // delay(100);
		  }*/
		  
		 // dprintf("%d",(int)distance);
		/***********************************
		**        reading sensors
		************************************/
		compass.read();
		dprintf("%d", int(compass.heading()));
		//dprintf("%d z",(int)(compass.a.z/16.0));
		
		/*if(compass.a.z/16.0<-1000){
		distFromStart += 33;
		step++;
		dprintf("%d step",step);	
		}*/
		/*  float heading = compass.heading();
		float XaVal, YaVal, ZaVal, fXa, fYa,fZa, pitch, roll,pitch_print, roll_print;
		const float alpha = 0.15;
		XaVal = compass.a.x/16.0; //Acceleration data registers contain a left-aligned 12-bit number, so values should be shifted right by 4 bits (divided by 16)
		YaVal = compass.a.y/16.0; //unit is in cm/s2
		ZaVal = compass.a.z/16.0;
		/***********************************
		**       keypad
		************************************/
		char key = keypad.getKey();

		//print out the key that is pressed 
		if (key != NO_KEY){
		// Serial.print("You have pressed ");
		Serial.println(key);
		}
		/***********************************
		**       altitude
		************************************/
		float pressure = ps.readPressureMillibars() + 248.5;
		float altitude = ps.pressureToAltitudeMeters(pressure);
		
		//dprintf("alt %d , pres %d",(int)altitude,(int)pressure);
		// Serial.print("Pressure is ");
		// Serial.print(pressure);
		//  Serial.println(" mbar");
		// Serial.print("Altitude is ");
		// Serial.print(altitude);// causes error
		// Serial.println(" m.");
		//dprintf("%d",(int)pressure);
		//dprintf("%d",(int)altitude);
		/******************************************************
		**  gyro meter reading
		******************************************************/
		gyro.read();
		/*Serial.println("Gyro meter ");
		Serial.print("X: ");
		Serial.print((int)gyro.g.x * 8.75 /1000);
		Serial.println(" degree/second");
		Serial.print("Y: ");
		Serial.print((int)gyro.g.y * 8.75 /1000);
		Serial.println(" degree/second");
		Serial.print("Z: ");
		Serial.print((int)gyro.g.z * 8.75 /1000);
		Serial.println(" degree/second");
		Serial.println("");*/
  
		//dprintf("x: %d",(int)(gyro.g.x * 8.75 /1000));
		//dprintf("y: %d",(int)(gyro.g.y * 8.75 /1000));
		//dprintf("z: %d",(int)(gyro.g.z * 8.75 /1000));
  
		/*******************************************************************
						get Headings
		When given no arguments, the heading() function returns the angular
		difference in the horizontal plane between a default vector and
		north, in degrees.
		/*
		When given no arguments, the heading() function returns the angular
		difference in the horizontal plane between a default vector and
		north, in degrees.
  
		The default vector is chosen by the library to point along the
		surface of the PCB, in the direction of the top of the text on the
		silkscreen. This is the +X axis on the Pololu LSM303D carrier and
		the -Y axis on the Pololu LSM303DLHC, LSM303DLM, and LSM303DLH
		carriers.
  
		To use a different vector as a reference, use the version of heading()
		that takes a vector argument; for example, use
  
		compass.heading((LSM303::vector<int>){0, 0, 1});
  
		to use the +Z axis as a reference.
  
		*******************************************************************/
		// String direction = "";
		/*if(heading>=340 || heading <= 20)
  
		dprintf("North"); // direction = "North";
		else if (heading>=70 && heading <= 110)
 
		dprintf("East"); //  direction = "East";
		else if (heading>=160 && heading <= 200)
 
		dprintf("South");   //direction = "South";
		else if (heading>=250 && heading <= 290)

		dprintf("West");  //  direction = "West";
    
    
		else if (heading>20 && heading < 70)
  
		dprintf("North East"); // direction = "North East";
		else if (heading>110 && heading < 160)
 
		dprintf("South East"); //  direction = "South East";
		else if (heading>200 && heading < 250)
   
		dprintf("South West");// direction = "South West";
		else if (heading>290 && heading < 340)
 
		dprintf("North West");  // direction = "North West";
	
		// Serial.print("Heading is ");
		//Serial.println(direction);
		//Serial.println("degree.");
		/******************************************************
		**  Method 1 to calculate distance: using steps
		******************************************************/
 
		// a step and  distance using Z-ACCELERATION
		/*  if(ZaVal<-950){
		distFromStart+=33;  //1 step is 33 cm
		step++; 
		} 

  
		/*  Serial.print("X accel is ");Serial.print(XaVal); Serial.print(" cm/s2"); Serial.println(" "); 
		Serial.print("Y accel is ");Serial.print(YaVal); Serial.print(" cm/s2"); Serial.println(" "); 
		Serial.print("Z accel is ");Serial.print(ZaVal);Serial.print(" cm/s2"); Serial.println(" "); 
   
 
		Serial.print("1. You have walked ");
		Serial.print(step);
		Serial.print(" steps and distance is ");
		Serial.print(distFromStart);
		Serial.println(" cm from start");*/


		/*dprintf("x accel %d", (int)XaVal); 
		dprintf("y accel %d",(int) YaVal); 
		dprintf("z accel %d", (int)ZaVal); */
	
	
		/******************************************************
		**  pitch and roll
		******************************************************/
		// Low-Pass filter accelerometer
		/*  fXa = XaVal * alpha + (fXa * (1.0 - alpha));
		fYa = YaVal * alpha + (fYa * (1.0 - alpha));
		fZa = ZaVal * alpha + (fZa * (1.0 - alpha));

		/* Serial.print("Low pass X accel is ");Serial.print(fXa); Serifal.print(" cm/s2"); Serial.println(" "); 
		Serial.print("Low pass Y accel is ");Serial.print(fYa); Serial.print(" cm/s2"); Serial.println(" "); 
		Serial.print("Low pass Z accel is ");Serial.print(fZa);Serial.print(" cm/s2"); Serial.println(" ");    */
    
		/* roll  = atan2(fYa, sqrt(fXa*fXa + fZa*fZa));
		pitch = atan2(fXa, sqrt(fYa*fYa + fZa*fZa));
  
		roll_print = roll*180.0/M_PI;
		pitch_print = pitch*180.0/M_PI;
		/* Serial.print("pitch(Y) is ");
		Serial.print(pitch_print);
		Serial.println("degree ");

		Serial.print("roll(X) is ");
		Serial.print(roll_print);
		Serial.println("degree ");*/
		/******************************************************
		**  Method 2 to calculate distance: using accelerations
		******************************************************/
		/*  newTime = millis();
		deltaTime = newTime - oldTime;
  
		XaVal = XaVal - (1000 * (sin(pitch)));//offsetting pitch 
  
		// estimate the average acceleration since the previous sample, by averaging the two samples
		long avgAccel = (oldXaVal + XaVal) / 2;
  
		//if ((XaVal < 50 && XaVal > -50) && (oldXaVal < 50 && oldXaVal > -50)) 
		//  avgAccel = 0;
  
 
		/* working
		Serial.print("the avgAccel is ");
		Serial.print(avgAccel);
		Serial.println(" cm/s2");*/
		// integrate the average accel and add it to the previous speed to calculate the new speed
		// long newVelocity = oldVelocity + (avgAccel  * deltaTime/1000);
 
   
		//estimate the average speed since the previous sample, by averaging the two speeds
		//long avgVelocity = (oldVelocity + newVelocity) / 2;
  
		//  if ((XaVal < 50 && XaVal > -50) && (oldXaVal < 50 && oldXaVal > -50)) 
		//  avgVelocity = 0;
  
  
		// integrate the average speed and add it to the previous displacement to get the new displacement
		/*  long newDisplacement = oldDis + (avgVelocity * deltaTime/1000);
  
		oldTime = newTime;
		oldVelocity = newVelocity ;
		oldDis = newDisplacement;
		oldXaVal = XaVal;*/
		/*working
		Serial.print("2. You have walked ");
		Serial.print(newDisplacement);
		Serial.println("cm from start");  */
  
		/******************************************************
		**  IR sensor meter reading
		******************************************************/
		sensorValue = analogRead(sensorIR);
		cm = 10650.08 * pow(sensorValue,-0.935) - 10;
		/* Serial.print("IR sensor reads ");
		Serial.print(cm);
		Serial.println(" Cm");*/
  
		//delay(100);
		vTaskDelay(100);
	}
}
Exemple #14
0
void task_sensor_poll(void* p){
	
  while(1){
  
  /***********************************
  **        reading sensors
  ************************************/
  compass.read();
 /* float heading = compass.heading();
  float XaVal, YaVal, ZaVal, fXa, fYa,fZa, pitch, roll,pitch_print, roll_print;
  const float alpha = 0.15;
  XaVal = compass.a.x/16.0; //Acceleration data registers contain a left-aligned 12-bit number, so values should be shifted right by 4 bits (divided by 16)
  YaVal = compass.a.y/16.0; //unit is in cm/s2
  ZaVal = compass.a.z/16.0;
  /*
   
  /***********************************
  **       keypad
  ************************************/
  char key = keypad.getKey();

  //print out the key that is pressed 
  if (key != NO_KEY){
    Serial.print("You have pressed ");
    Serial.println(key);
  }

  /***********************************
  **       altitude
  ************************************/
  float pressure = ps.readPressureMillibars() + 248.5;
  float altitude = ps.pressureToAltitudeMeters(pressure);
  
/*  Serial.print("Pressure is ");
  Serial.print(pressure);
  Serial.println(" mbar");
  Serial.print("Altitude is ");
  Serial.print(altitude);
  Serial.println(" m.");
  
  /******************************************************
  **  gyro meter reading
  ******************************************************/
  gyro.read();
/*  Serial.println("Gyro meter ");
  Serial.print("X: ");
  Serial.print((int)gyro.g.x * 8.75 /1000);
  Serial.println(" degree/second");
  Serial.print("Y: ");
  Serial.print((int)gyro.g.y * 8.75 /1000);
  Serial.println(" degree/second");
  Serial.print("Z: ");
  Serial.print((int)gyro.g.z * 8.75 /1000);
  Serial.println(" degree/second");
  Serial.println("");




 /*******************************************************************
                          get Headings
  When given no arguments, the heading() function returns the angular
  difference in the horizontal plane between a default vector and
  north, in degrees.
  /*
  When given no arguments, the heading() function returns the angular
  difference in the horizontal plane between a default vector and
  north, in degrees.
  
  The default vector is chosen by the library to point along the
  surface of the PCB, in the direction of the top of the text on the
  silkscreen. This is the +X axis on the Pololu LSM303D carrier and
  the -Y axis on the Pololu LSM303DLHC, LSM303DLM, and LSM303DLH
  carriers.
  
  To use a different vector as a reference, use the version of heading()
  that takes a vector argument; for example, use
  
    compass.heading((LSM303::vector<int>){0, 0, 1});
  
  to use the +Z axis as a reference.
  
  *******************************************************************/
 /* String direction = "";
  if(heading>=340 || heading <= 20)
    direction = "North";
  else if (heading>=70 && heading <= 110)
    direction = "East";
    else if (heading>=160 && heading <= 200)
    direction = "South";
    else if (heading>=250 && heading <= 290)
    direction = "West";
    
    
    else if (heading>20 && heading < 70)
    direction = "North East";
    else if (heading>110 && heading < 160)
    direction = "South East";
    else if (heading>200 && heading < 250)
    direction = "South West";
    else if (heading>290 && heading < 340)
    direction = "North West";
  
  Serial.print("Heading is ");
  Serial.println(direction);
  //Serial.println("degree.");
 
 
 /******************************************************
  **  Method 1 to calculate distance: using steps
  ******************************************************/
 
  // a step and  distance using Z-ACCELERATION
/*  if(ZaVal<-965){
    distFromStart+=33;  //1 step is 33 cm
    step++; 
  } 

  
  Serial.print("X accel is ");Serial.print(XaVal); Serial.print(" cm/s2"); Serial.println(" "); 
  Serial.print("Y accel is ");Serial.print(YaVal); Serial.print(" cm/s2"); Serial.println(" "); 
  Serial.print("Z accel is ");Serial.print(ZaVal);Serial.print(" cm/s2"); Serial.println(" "); 
   
 
  Serial.print("1. You have walked ");
  Serial.print(step);
  Serial.print(" steps and distance is ");
  Serial.print(distFromStart);
  Serial.println(" cm from start");
  
 /******************************************************
  **  pitch and roll
  ******************************************************/
    // Low-Pass filter accelerometer
/*  fXa = XaVal * alpha + (fXa * (1.0 - alpha));
  fYa = YaVal * alpha + (fYa * (1.0 - alpha));
  fZa = ZaVal * alpha + (fZa * (1.0 - alpha));

  Serial.print("Low pass X accel is ");Serial.print(fXa); Serial.print(" cm/s2"); Serial.println(" "); 
  Serial.print("Low pass Y accel is ");Serial.print(fYa); Serial.print(" cm/s2"); Serial.println(" "); 
  Serial.print("Low pass Z accel is ");Serial.print(fZa);Serial.print(" cm/s2"); Serial.println(" ");    
    
  roll  = atan2(fYa, sqrt(fXa*fXa + fZa*fZa));
  pitch = atan2(fXa, sqrt(fYa*fYa + fZa*fZa));
  
  roll_print = roll*180.0/M_PI;
  pitch_print = pitch*180.0/M_PI;
  Serial.print("pitch(Y) is ");
  Serial.print(pitch_print);
  Serial.println("degree ");

  Serial.print("roll(X) is ");
  Serial.print(roll_print);
  Serial.println("degree ");
  
 /******************************************************
  **  Method 2 to calculate distance: using accelerations
  ******************************************************/
  //newTime = millis();
 /* deltaTime = newTime - oldTime;
  
   XaVal = XaVal - (1000 * (sin(pitch)));//offsetting pitch 
  
  // estimate the average acceleration since the previous sample, by averaging the two samples
  long avgAccel = (oldXaVal + XaVal) / 2;
  
  //if ((XaVal < 50 && XaVal > -50) && (oldXaVal < 50 && oldXaVal > -50)) 
  //  avgAccel = 0;
  
 
  
/*  Serial.print("the avgAccel is ");
  Serial.print(avgAccel);
  Serial.println(" cm/s2");
  // integrate the average accel and add it to the previous speed to calculate the new speed
  long newVelocity = oldVelocity + (avgAccel  * deltaTime/1000);
 
   
  //estimate the average speed since the previous sample, by averaging the two speeds
  long avgVelocity = (oldVelocity + newVelocity) / 2;
  
  //  if ((XaVal < 50 && XaVal > -50) && (oldXaVal < 50 && oldXaVal > -50)) 
  //  avgVelocity = 0;
  
  
  // integrate the average speed and add it to the previous displacement to get the new displacement
  long newDisplacement = oldDis + (avgVelocity * deltaTime/1000);
  
  oldTime = newTime;
  oldVelocity = newVelocity ;
  oldDis = newDisplacement;
  oldXaVal = XaVal;
  Serial.print("2. You have walked ");
  Serial.print(newDisplacement);
  Serial.println("cm from start");  
   


  /******************************************************
  **  IR sensor meter reading
  ******************************************************/
  sensorValue = analogRead(sensorIR);
  cm = 10650.08 * pow(sensorValue,-0.935) - 10;
/*  Serial.print("IR sensor reads ");
  Serial.print(cm);
  Serial.println(" Cm");
  
  
  
    /***********************************
  **        reading sensors
  ************************************/
  /*
  //digitalWrite(ECHO_PIN2 ,LOW);
  unsigned int uS2 = sonar2.ping();
  
  Serial.print("Sonar 2: ");
  Serial.print(sonar2.convert_cm(uS2));
  Serial.println("cm");
    if(sonar2.convert_cm(uS2)<50){
    digitalWrite(MOTOR, HIGH);     // waits for a second
        // sets the LED off
    //delay(1000);                  // waits for a second
  }
  else{
   digitalWrite(MOTOR, LOW);
  }
  //delay(100);
*/
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */ 
 digitalWrite(TRIGGER_PIN, LOW); 
 delayMicroseconds(2); 

 digitalWrite(TRIGGER_PIN, HIGH);
 delayMicroseconds(10); 
 
 digitalWrite(TRIGGER_PIN, LOW);
 duration = pulseIn(ECHO_PIN, HIGH);
 
 //Calculate the distance (in cm) based on the speed of sound.
 distance = duration/58.2;
 dprintf("%d",(int)distance);
/* Serial.print("sonar distance is ");
 Serial.println(distance);
 Serial.println();*/
 if (distance >= 10 && distance <= 70){
 /* Send a negative number to computer and Turn LED ON 
 to indicate "out of range" */
 //Serial.println("-1");
 digitalWrite(MOTOR, HIGH); 
 }
 else {
 /* Send the distance to the computer using Serial protocol, and
 turn LED OFF to indicate successful reading. */
 //Serial.println(distance);
 digitalWrite(MOTOR, LOW); 
 }
 
 //Delay 50ms before next reading.
 delay(50);
  }
}
Exemple #15
0
//===============================================================================
void running() {

    if(programed == true) {
        switch(statea) {
        case 1:
            lcd.setCursor(0, 0);
            lcd.print("     Armed      ");
            lcd.setCursor(0, 1);

            if((keyBool == true) && (keyDis != true)) {
                lcd.print("K=");
                if((digitalRead(largeKey) == HIGH) && (lKey == true)) {
                    keyDis = true;
                    lcd.print("D");
                }
                else if((digitalRead(largeKey) == LOW) && (lKey == false)) {
                    keyDis = true;
                    lcd.print("D");
                }
                else
                    lcd.print("A");
            }

            if((keypadBool == true) && (keypadDis != true)) {

                but = keypadA.getKey();

                if((but != NO_KEY) && (i < 4)) {
                    butt[i] = but;
                    i++;
                    if(i == 4) {
                        if((code[0] == butt[0]) && (code[1] == butt[1]) && (code[2] == butt[2]) && (code[3] == butt[3]))
                            keypadDis = true;
                        else {
                            butt[0] = '-';
                            butt[1] = '-';
                            butt[2] = '-';
                            butt[3] = '-';
                            i = 0;
                            if(attem == true) {
                                attemCount--;
                                if(attemCount == 0) {
                                    bang = true;
                                }
                            }
                        }
                    }
                    but = '-';
                }
                lcd.print(butt[0]);
                lcd.print(butt[1]);
                lcd.print(butt[2]);
                lcd.print(butt[3]);
                lcd.print(" ");
                lcd.print(attemCount);
            }

            if(wireBool == true) {
                if((digitalRead(wire1) == LOW) && (safeWire == 1))
                    wireDis = true;
                else if((digitalRead(wire1) == LOW) && (safeWire != 1))
                    bang = true;

                if((digitalRead(wire2) == LOW) && (safeWire == 2))
                    wireDis = true;
                else if((digitalRead(wire2) == LOW) && (safeWire != 2))
                    bang = true;

                if((digitalRead(wire3) == LOW) && (safeWire == 3))
                    wireDis = true;
                else if((digitalRead(wire3) == LOW) && (safeWire != 3))
                    bang = true;

                if((digitalRead(wire4) == LOW) && (safeWire == 4))
                    wireDis = true;
                else if((digitalRead(wire4) == LOW) && (safeWire != 4))
                    bang = true;
            }

            if(bang == true) {
                statea = 3;
            }

            if((wireDis == true) || ((keyDis == keyBool) && (keypadDis == keypadBool))) {
                statea = 2;
            }
            break;

        case 2://Disarmed
            lcd.setCursor(0, 0);
            lcd.print("    Disarmed    ");
            lcd.setCursor(0, 1);
            lcd.print("                ");
            break;

        case 3://Bang
            lcd.setCursor(0, 0);
            lcd.print("      BANG      ");
            lcd.setCursor(0, 1);
            lcd.print("    You lose    ");
            break;
        }
    }
    else {
        lcd.setCursor(0, 0);
        lcd.print("Not configured");
        lcd.setCursor(0, 1);
        lcd.print("                ");
    }
}
void loop()
{
  key = 0;
  key = my_keypad.getKey();
  while(!key)
  {
    lcd.setCursor(0,0);
    lcd.print("Press any key...");
    lcd.setCursor(0,1);
    lcd.print(".....to Proceed.");
    key = my_keypad.getKey();
    if(key)  break;
  }
  
  lcd.clear();
  lcd.print("Enter Code:");
  key = my_keypad.getKey();
  int i=0;
      key=0;
        while(i<4)         // there are only four digit code
        {
          key = my_keypad.getKey();  // Read Key from keypad
          if(key)                    // if Key value is not zero
          {
            code_user[i]=key;        // then store the first digit first array element
            i++;                    
            lcd.setCursor(i,1);
            lcd.print("*");          // Display '*' (Asterik) at each key stroke
          }
          key=0;                     // initiliaze key value for next key stroke
        }
        delay(500);                  // wait for half second after all key are pressed
        int count = 0;               // define a new count variable to compare two arrays
        for(i=0; i<4; i++)           // i.e. one EEPROM and other code_user
        {
          if(EEPROM.read(i) == code_user[i])  count++;  // Compare each code here
        }
        if(count == 4)
        {
          while(~key)
          {
            //lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("1.LOCK  "); // A menu view of the system 
            lcd.print("2.UNLOCK");
            lcd.setCursor(0,1);        // at the begning
            lcd.print("3.CHANGE CODE ");
            key = my_keypad.getKey();
            if(key)  break;
          }
          
          switch(key)
          {
            case '1':
            {
               lcd.clear();
               lcd.print("Closing Door...");
               digitalWrite(motor_BW, HIGH);
               digitalWrite(motor_FW, LOW);
               delay(1000); // for 2 seconds
               digitalWrite(motor_BW, LOW);
               break;
             }
             
             case '2' :
             {
               
               
              lcd.clear();
              lcd.print("Opening Door....");
              digitalWrite(motor_FW, HIGH);
              digitalWrite(motor_BW, LOW);
              delay(1000); // for 2 seconds
              digitalWrite(motor_FW, LOW);
              break;
             }
             
             case'3':
             {
               lcd.clear();
               lcd.print("Enter New Code.");
               i = key = 0;
               while(i<4)
               {
                  key = my_keypad.getKey();
                  if(key)
                  {
                    code_temp[i] = key;  
                    i++;
                    lcd.setCursor(i,1);
                    lcd.print("*");
                  }
                  key=0;
               }
               delay(500); 
               lcd.clear();
               lcd.print("Verify New Code.");
               i = key = count = 0;
               while(i<4)
               {
                  key = my_keypad.getKey();
                  if(key)
                  {
                    if(code_temp[i] == key)
                    {
                      count++;
                    }
                    i++;
                    lcd.setCursor(i,1);
                    lcd.print("*");
                   }
                   key=0;
                }
                delay(500);
                if(count==4)
                {
                   for(i=0; i<4; i++)
                   {
                      EEPROM.write(i,code_temp[i]);
                   }
                   lcd.clear();
                   lcd.setCursor(6,0);
                   lcd.print("DONE!");
                 }
                 else
                {
                  lcd.clear();
                  lcd.setCursor(4,0);
                  lcd.print("NOT DONE!");
                }
                delay(500);
               break;
             }
          }
        }
        else
        {
          lcd.clear();
          lcd.print("DID NOT MATCHED!");
          chance++;
          if(chance>=3)
          {
            chance = 0;
            lcd.clear();
            lcd.print("ACCESS DENIED!");
            lcd.setCursor(0,1);
            lcd.print("Try later!");
            digitalWrite(buzzer, HIGH);
            delay(3000);
            digitalWrite(buzzer, LOW);
//            tone(buzzer, 500);
//            delay(3000);
//            noTone(buzzer);
          }
          delay(500);
        }      
}
Exemple #17
0
// Process buttons:
void procButton(KeypadEvent b) {
    b -= 48;
    switch (keypad.getState()) {
    case RELEASED: // drop right away
        return;
    case PRESSED: // momentary
        if(mode==2) { // Signal Switching 4
            ss4Signal(b);
            break;
        } else if(mode==3) {
            pulse(b); // pulse it
            return;
        }
        if(mode==4&&(b<10&&b>=0||b==-13||b==-6||(b>=49&&b<=52))) { // MF tone
            mf(b);
        }
        if(b<10&&b>=0||b==-13||b==-6) { // MF tone
            mf(b);
        } else if(b==52) { // D
            if (stored) playStored(); // don't copy function onto stack if not needed
            return;
        } else if(mode==1) { // international kp2/st2
            if(b>=49&&b<=51) {
                mf(b);
                return;
            }
        }
        else if(mode==0&&(b<=51&&b>=49)) { // A,B,C redbox
            redBox(b); // pass it to RedBox()
            return;
        }
        break;
    case HOLD: // HELD (special functions)
        if(b==50&&mode==3) { // HOLD B for MF2 in PD Mode
            (mf2)? mf2 = 0 : mf2 = 1; // turn off if on, or on if off
            freq[0].play(440,70);
            delay(140);
            freq[0].play(440,70);
            delay(140);
        }
        if(b<10&&b>=0||b==-13||b==-6) {
            dial(b);
        } else if(b==51) { // C takes care of recording now
            if(rec) { // we are done recording:
                digitalWrite(13, LOW); // turn off LED
                rec = 0;
                stored=1; // we have digits stored
                recNotify();
            } else { // we start recording
                digitalWrite(13, HIGH); // light up LED
                rec = 1;
                for(int i=0; i<=23; i++) { // reset array
                    store[i] = -1;
                }
                recNotify();
            } // END recording code
        } else if(b==49) { // ('A' HELD) switching any mode "on" changes to mode, all "off" is domestic
            if(mode==0) { // mf to international
                mode=1;
            } else if(mode==1) { // international to ss4 mode
                mode=2;
            } else if(mode==2) { // ss4 mode to pulse mode
                mode=3;
            } else if(mode==3) { // pulse mode to DTMF
                mode=4;
            } else if(mode==4) { // DTMF to domestic
                mode=0;
            }
            notifyMode();
            return;
        }
        break;
    }
    return;
}