KL46 CapKey program with selectable channels for elements of exhibit design class.
Fork of CapKey_46_v1_button by
cdg_main.cpp
00001 #include "mbed.h" 00002 #include "SLCD.h" 00003 00004 //Dating Game Capkey controller 07/16/2013 sc 00005 // Modified for mbet KL46Z 10/07/2014 00006 // Four inputs and Four relays 00007 // Changed to simulate capkeys with the KL on board buttons 00008 #define PROGNAME "DG Cap Key v1.1\r\n" 00009 #define KEYHIT "SND" 00010 #define SERIAL_SPEED 9600 00011 #define HIGH 1 00012 #define LOW 0 00013 #define RESET_DELAY 1200 00014 #define RELAY_ON HIGH 00015 #define RELAY_OFF LOW 00016 #define LED_ON LOW 00017 #define LED_OFF HIGH 00018 #define DEBOUNCE 50 00019 #define NUMREL 4 // really just the number of outputs 00020 #define LCDDELAY 0.200 00021 #define COUNTERLIMIT 300 00022 00023 00024 DigitalOut Relays[NUMREL] = {D10,D11,D12,D13}; // corresponds to touches 1,2,3,4 00025 //DigitalIn capKeys[NUMREL] = {D2,D4,D6,D8}; 00026 DigitalOut capRST[NUMREL] = {D3,D5,D7,D9}; 00027 DigitalIn sendKey(PTC3); // on board buttons just use 1 for test 00028 00029 00030 00031 00032 Timer millis; 00033 Serial pc(USBTX, USBRX); 00034 SLCD slcd; //define LCD display 00035 InterruptIn chanButton(PTC12); 00036 int channelSelect=0; 00037 int channelDisplay = 1; 00038 00039 // variables will change: 00040 int buttonState = true; 00041 long relayTimeout; 00042 long capKeyTimeout; 00043 int LCDCounter = 0; 00044 00045 void getChannel() { // button interrupt 00046 channelSelect = (channelSelect + 1) % NUMREL; 00047 channelDisplay = channelSelect +1; 00048 } 00049 00050 void LCDMess(char *lMess, float dWait){ 00051 slcd.Home(); 00052 slcd.clear(); 00053 slcd.printf(lMess); 00054 wait(dWait); 00055 } 00056 // variable for reading the pushbutton status 00057 00058 int main() { 00059 int i; 00060 int buttonVal = 0; 00061 00062 char lcdData[10]; //buffer needs places dor decimal pt and colon 00063 00064 int OKtoRead = true; 00065 00066 chanButton.fall(&getChannel); 00067 00068 // initialize the LED pin as an output: 00069 millis.start(); 00070 millis.reset(); 00071 00072 pc.printf(PROGNAME); 00073 for (i=0; i<NUMREL; i++){ 00074 Relays[i].write(RELAY_OFF); 00075 capRST[i].write(HIGH); 00076 } 00077 00078 while (true) { 00079 // Show active channel 00080 00081 sprintf (lcdData,"CH-%1d",channelDisplay); 00082 LCDMess(lcdData, LCDDELAY); 00083 00084 // read the state of the pushbutton value: 00085 if(OKtoRead) { 00086 buttonVal = !sendKey.read() ; // on board buttons just use 1 00087 if (buttonVal){ 00088 sprintf (lcdData,"SND%1d",channelDisplay); 00089 LCDMess(lcdData, LCDDELAY); 00090 Relays[channelSelect].write(RELAY_ON); 00091 capRST[channelSelect].write(LOW); //reset the cap key 00092 pc.printf("Relay = %d \n\r", channelSelect); 00093 millis.reset(); 00094 relayTimeout = RESET_DELAY; 00095 OKtoRead = false; 00096 00097 } 00098 }//end OKtoRead 00099 00100 if (millis.read_ms() > relayTimeout) { 00101 OKtoRead = true; 00102 for (i=0; i<NUMREL; i++){ 00103 Relays[i].write(RELAY_OFF); 00104 capRST[i].write(HIGH); 00105 } 00106 } 00107 00108 }// end forever while 00109 } // end main
Generated on Wed Jul 20 2022 19:57:25 by 1.7.2