TestKeypad

Dependencies:   Hotboards_keypad TextLCD mbed

Fork of Chronometer_V2 by VR FabLab - RoboVal

Committer:
Ghiri
Date:
Mon Mar 26 21:13:28 2018 +0000
Revision:
1:26bcd89c18e5
Parent:
0:1a92e4a37697
Keypad program test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ghiri 0:1a92e4a37697 1 //##############################################################
Ghiri 0:1a92e4a37697 2 //##
Ghiri 0:1a92e4a37697 3 //## Event: RoboVal - Robot Race
Ghiri 0:1a92e4a37697 4 //##
Ghiri 0:1a92e4a37697 5 //## Chronometer double use
Ghiri 0:1a92e4a37697 6 //##
Ghiri 0:1a92e4a37697 7 //## Version 1.99A
Ghiri 0:1a92e4a37697 8 //##
Ghiri 0:1a92e4a37697 9 //## Hardware platform used: ST NUCLEO-F401RE
Ghiri 0:1a92e4a37697 10 //##
Ghiri 0:1a92e4a37697 11 //## Software IDE used: mbed online version
Ghiri 0:1a92e4a37697 12 //##
Ghiri 0:1a92e4a37697 13 //## Organizzation: Verona FabLab
Ghiri 0:1a92e4a37697 14 //##
Ghiri 0:1a92e4a37697 15 //## Date creation: 2018.01.01
Ghiri 0:1a92e4a37697 16 //##
Ghiri 0:1a92e4a37697 17 //## Software developpers: FdF,GV, AG
Ghiri 0:1a92e4a37697 18 //##
Ghiri 0:1a92e4a37697 19 //## Base on original version of by FdF
Ghiri 0:1a92e4a37697 20 //##
Ghiri 0:1a92e4a37697 21 //##############################################################
Ghiri 0:1a92e4a37697 22
Ghiri 0:1a92e4a37697 23 #include <stdlib.h>
Ghiri 0:1a92e4a37697 24 #include "mbed.h"
Ghiri 0:1a92e4a37697 25 #include "TextLCD.h"
Ghiri 1:26bcd89c18e5 26 #include "Hotboards_keypad.h"
Ghiri 0:1a92e4a37697 27
Ghiri 0:1a92e4a37697 28
Ghiri 0:1a92e4a37697 29 // Default Number Lap
Ghiri 0:1a92e4a37697 30 #define NUM_LAP 3
Ghiri 0:1a92e4a37697 31
Ghiri 0:1a92e4a37697 32 // Reference for Low/Min Voltage battery
Ghiri 0:1a92e4a37697 33 #define VBAT_MIN 7.2
Ghiri 0:1a92e4a37697 34
Ghiri 1:26bcd89c18e5 35 // Defines the keys array with it's respective number of rows & cols,
Ghiri 1:26bcd89c18e5 36 // and with the value of each key
Ghiri 1:26bcd89c18e5 37 char keys[ 4 ][ 4 ] =
Ghiri 1:26bcd89c18e5 38 {
Ghiri 1:26bcd89c18e5 39 { '1' , '2' , '3' , 'A' },
Ghiri 1:26bcd89c18e5 40 { '4' , '5' , '6' , 'B' },
Ghiri 1:26bcd89c18e5 41 { '7' , '8' , '9' , 'C' },
Ghiri 1:26bcd89c18e5 42 { '*' , '0' , '#' , 'D' }
Ghiri 1:26bcd89c18e5 43 };
Ghiri 0:1a92e4a37697 44
Ghiri 1:26bcd89c18e5 45 // Pin keypad 4x4
Ghiri 1:26bcd89c18e5 46 // 1, 2, 3, 4, 5, 6, 7, 8
Ghiri 1:26bcd89c18e5 47 // C4, C3, C2, C1, R4, R3, R2, R1
Ghiri 1:26bcd89c18e5 48 // PB_0, PA_4 , PA_1 , PA_0, PA_13, PA_14, PC_14, PC_15
Ghiri 1:26bcd89c18e5 49 // PC_15, PC_14, PA_14, PA_13, PA_0, PA_1, PA_4, PB_0
Ghiri 1:26bcd89c18e5 50 //
Ghiri 1:26bcd89c18e5 51 // Defines the pins connected to the rows
Ghiri 1:26bcd89c18e5 52 DigitalInOut rowPins[ 4 ] = { PB_0 , PA_4 , PA_1 , PA_0 };
Ghiri 1:26bcd89c18e5 53
Ghiri 1:26bcd89c18e5 54 // Defines the pins connected to the cols
Ghiri 1:26bcd89c18e5 55 DigitalInOut colPins[ 4 ] = { PB_0 , PA_4 , PA_1 , PA_0 };
Ghiri 0:1a92e4a37697 56
Ghiri 1:26bcd89c18e5 57 // Creates a new keyboard with the values entered before
Ghiri 1:26bcd89c18e5 58 Keypad kpd( makeKeymap( keys ) , rowPins , colPins , 4 , 4 );
Ghiri 1:26bcd89c18e5 59
Ghiri 1:26bcd89c18e5 60 // Configures the serial port
Ghiri 1:26bcd89c18e5 61 Serial pc( USBTX , USBRX );
Ghiri 1:26bcd89c18e5 62
Ghiri 1:26bcd89c18e5 63
Ghiri 0:1a92e4a37697 64
Ghiri 0:1a92e4a37697 65 // read Voltage battery
Ghiri 0:1a92e4a37697 66 DigitalOut heartbeat(LED1);
Ghiri 0:1a92e4a37697 67
Ghiri 0:1a92e4a37697 68 // read Voltage battery, analog pin used PC_3 (Pin 37 of Morpho layout)
Ghiri 1:26bcd89c18e5 69 //AnalogIn vbat(PC_3);
Ghiri 0:1a92e4a37697 70
Ghiri 0:1a92e4a37697 71 // User button pressure
Ghiri 0:1a92e4a37697 72 InterruptIn user_button(USER_BUTTON);
Ghiri 0:1a92e4a37697 73
Ghiri 0:1a92e4a37697 74 // Sensor connected to digital input D9, alias PC7 on Morpho layout
Ghiri 1:26bcd89c18e5 75 // Now p29 and p31
Ghiri 0:1a92e4a37697 76 InterruptIn proximity(D9);
Ghiri 1:26bcd89c18e5 77
Ghiri 0:1a92e4a37697 78
Ghiri 0:1a92e4a37697 79 // LCD Display (RS, E, D4, D5, D6, D7);
Ghiri 0:1a92e4a37697 80 TextLCD lcd(D2,D3,D4,D5,D6,D7);
Ghiri 0:1a92e4a37697 81
Ghiri 0:1a92e4a37697 82
Ghiri 0:1a92e4a37697 83
Ghiri 0:1a92e4a37697 84
Ghiri 0:1a92e4a37697 85 //------------------------------------------------------------
Ghiri 0:1a92e4a37697 86 //
Ghiri 0:1a92e4a37697 87 // Main body
Ghiri 0:1a92e4a37697 88 //
Ghiri 0:1a92e4a37697 89 //------------------------------------------------------------
Ghiri 0:1a92e4a37697 90
Ghiri 0:1a92e4a37697 91 int main() {
Ghiri 0:1a92e4a37697 92
Ghiri 0:1a92e4a37697 93 proximity.mode(PullDown);
Ghiri 1:26bcd89c18e5 94
Ghiri 0:1a92e4a37697 95
Ghiri 1:26bcd89c18e5 96 while(true) {
Ghiri 0:1a92e4a37697 97
Ghiri 0:1a92e4a37697 98 lcd.locate(0,0);
Ghiri 1:26bcd89c18e5 99 lcd.printf("Character: ");
Ghiri 0:1a92e4a37697 100
Ghiri 0:1a92e4a37697 101 heartbeat = !heartbeat;
Ghiri 1:26bcd89c18e5 102
Ghiri 1:26bcd89c18e5 103 // Poll the keypad to look for any activation
Ghiri 1:26bcd89c18e5 104 char key = kpd.getKey( );
Ghiri 0:1a92e4a37697 105
Ghiri 1:26bcd89c18e5 106 // If any key was pressed
Ghiri 1:26bcd89c18e5 107 if( key )
Ghiri 1:26bcd89c18e5 108 {
Ghiri 1:26bcd89c18e5 109 // Display the key pressed on serial port
Ghiri 1:26bcd89c18e5 110 lcd.locate(0,1);
Ghiri 1:26bcd89c18e5 111 lcd.printf( "%c" , key );
Ghiri 1:26bcd89c18e5 112 //lcd.printf( "\n\r" );
Ghiri 0:1a92e4a37697 113 }
Ghiri 0:1a92e4a37697 114 }
Ghiri 0:1a92e4a37697 115 }
Ghiri 0:1a92e4a37697 116