本文整理汇总了C++中Keypad::getKey方法的典型用法代码示例。如果您正苦于以下问题:C++ Keypad::getKey方法的具体用法?C++ Keypad::getKey怎么用?C++ Keypad::getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Keypad
的用法示例。
在下文中一共展示了Keypad::getKey方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: keyPresets
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");
}
}
}
示例2: loop
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
Serial.println(key);
}
}
示例3: loop
// 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()
}
示例4: task_keypad
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*/
}
示例5: loop
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
}
}
}
示例6: main
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;
}
示例7: main
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);
}
}
示例8: loop
// --- 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;
}
示例9: task_poll_sensor
//.........这里部分代码省略.........
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");
示例10: task_sensor_poll
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";
//.........这里部分代码省略.........
示例11: program
//===============================================================================
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);
//.........这里部分代码省略.........
示例12: running
//===============================================================================
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);
//.........这里部分代码省略.........
示例13: loop
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)
{
//.........这里部分代码省略.........