Team Kryptonite EE300 Keypad Subsystem
Fork of mbed_can_bus_test1 by
main.cpp
- Committer:
- Googlesomething
- Date:
- 2017-12-01
- Revision:
- 2:02021bd6b07e
- Parent:
- 1:907c82f7f923
- Child:
- 3:e019f1954b2a
File content as of revision 2:02021bd6b07e:
#include "mbed.h" #include "Keypad.h" Ticker ticker; Serial PC(USBTX, USBRX); DigitalOut led1(LED1); DigitalOut led2(LED2); CAN can1(p9,p10); CAN can2(p30,p29); DigitalIn pin21(p21); DigitalIn pin22(p22); DigitalIn pin23(p23); DigitalIn pin24(p24); DigitalIn pin25(p25); DigitalIn pin26(p26); DigitalIn pin27(p27); //Declare KeyPad GPIO pins here char Keytable[] = { '1', '2', '3', //row0, p1, mbedpin21 '4', '5', '6', //row1, p2, mbedpin22 '7', '8', '9', //row2, p3, mbedpin23 '*', '0', '#', //row3, p4, mbedpin24 }; //col0, col1, col2 //p5, p6, p7 //mbedpin25, mbedpin26, mbedpin27 int32_t Index =-1; int State; uint32_t cbAfterInput(uint32_t _index) { Index = _index; return 0; } //Universal ID: 1337 //CAN Message Info char counter = 0; //keypad system CAN test variable char start = '*'; //Start char stop = '#'; //Stop / Reset char amp5 = 5; //Digipot char amp4 = 4; //Digipot char amp3 = 3; //Digipot char amp2 = 2; //Digipot char amp1 = 1; //Digipot char sin10Hz = 'q'; //DAC -6 char sin1Hz = 'w'; //DAC -7 char sqr10Hz = 'o'; //DAC -8 char sqr1Hz = 't'; //DAC -9 char saveUSB = 'u'; //ADC -0 char saveLocal = 'l'; //ADC That's an l as in labeorphily char keypress; //CAN Send (Parameter = message data) void send(char sendMsg) { if(can1.write(CANMessage(1337, &sendMsg, 1))) { printf("Message sent: %d\n", sendMsg); } led1 = !led1; } /* write Switch statements*/ //Setup Choice Switch Statements int main() { State = 1; // r0 r1 r2 r3 c0 c1 c2 c3 Keypad keypad(p21, p22, p23, p24, p25, p26, p27, NC); keypad.attach(&cbAfterInput); keypad.start(); // energize the columns c0-c3 of the keypad while (1) { __wfi(); if (Index > -1) { PC.printf("Interrupted"); PC.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]); Index = -1; printf("here2"); } printf("Please choose waveform:\n1: 1V \n2: 2V \n3: 3V \n4: 4V \n5: 5V \n6: 10Hz, Sine wave"); printf("\n7: 1Hz, Sine Wave\n8: 10Hz, Square Wave \n9: 1Hz, Square wave \n0: Save to USB \n*: Start Waveform Generation \n#: Stop/Reset Waveform\n"); while(1) { keypress = Keytable[Index]; switch(keypress) { case 1 : send(amp1); Index=-1; printf("here1"); break; //optional case 2 : send(amp2); Index=-1; break; //optional case 3 : send(amp3); Index=-1; break; //Optional case 4 : send(amp4); Index=-1; break; case 5 : send(amp5); Index=-1; break; case 6 : send(sin10Hz); Index=-1; break; case 7 : send(sin1Hz); Index=-1; break; case 8 : send(sqr10Hz); Index=-1; break; case 9 : send(sqr1Hz); Index=-1; break; case 0 : send(saveUSB); Index=-1; break; case '*' : send(start); Index=-1; break; case '#' : send(stop); Index=-1; break; }; } /*CANMessage msg; while(1) { if(can2.read(msg)) { printf("Message Recieved: %d\n\n", msg.data[0]); led2 = !led2; } wait(0.2); }*/ } }