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