Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of CapKey_46_v1_button by
Revision 0:8a169bac9011, committed 2014-10-20
- Comitter:
- scohennm
- Date:
- Mon Oct 20 21:02:24 2014 +0000
- Child:
- 1:232e3f430f69
- Commit message:
- NMHU and NMMNHS capactive key program interface to Raspberry Pi
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SLCD.lib Mon Oct 20 21:02:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cdg_main.cpp Mon Oct 20 21:02:24 2014 +0000
@@ -0,0 +1,115 @@
+#include "mbed.h"
+#include "SLCD.h"
+
+//Dating Game Capkey controller 07/16/2013 sc
+// Modified for mbet KL46Z 10/07/2014
+// Four inputs and Four relays
+#define PROGNAME "DG Cap Key v1.1\r\n"
+#define KEYHIT "KEY1"
+#define SERIAL_SPEED 9600
+#define HIGH 1
+#define LOW 0
+#define RESET_DELAY 1500
+#define RELAY_ON HIGH
+#define RELAY_OFF LOW
+#define LED_ON LOW
+#define LED_OFF HIGH
+#define DEBOUNCE 50
+#define NUMREL 4
+#define LCDDELAY 0.200
+#define COUNTERLIMIT 300
+
+// constants won't change. They're used here to
+// set pin numbers:
+//const int buttonPin = PUSH2;
+
+
+DigitalOut Relays[NUMREL] = {D10,D11,D12,D13}; // corresponds to touches 1,2,3,4
+DigitalIn capKeys[NUMREL] = {D2,D4,D6,D8};
+DigitalOut capRST[NUMREL] = {D3,D5,D7,D9};
+/*
+DigitalOut Relays[NUMREL] = {D10}; // corresponds to touches 1,2,3,4
+DigitalIn capKeys[NUMREL] = {D2};
+DigitalOut capRST[NUMREL] = {D3,};
+*/
+DigitalOut RLed(LED_RED);
+DigitalOut GLed(LED_GREEN);
+
+Timer millis;
+Serial pc(USBTX, USBRX);
+SLCD slcd; //define LCD display
+
+// variables will change:
+int buttonState = true;
+long relayTimeout;
+long capKeyTimeout;
+int LCDCounter = 0;
+
+void LCDMess(char *lMess, float dWait){
+ slcd.Home();
+ slcd.clear();
+ slcd.printf(lMess);
+ wait(dWait);
+}
+// variable for reading the pushbutton status
+
+int main() {
+ int i;
+ int buttonVal = 0;
+ int buttonVal2 = 0;
+ int ledState = LED_ON;
+ char lcdData[10]; //buffer needs places dor decimal pt and colon
+
+ int OKtoRead = true;
+ // initialize the LED pin as an output:
+ millis.start();
+ millis.reset();
+
+ pc.printf(PROGNAME);
+ for (i=0; i<NUMREL; i++){
+ Relays[i].write(RELAY_OFF);
+ capRST[i].write(HIGH);
+ }
+
+ while (true) {
+ // For dramatic effect
+ ledState = !ledState;
+ LCDCounter++;
+ LCDCounter = LCDCounter % COUNTERLIMIT;
+ sprintf (lcdData,"%3d",LCDCounter);
+ LCDMess(lcdData, LCDDELAY);
+ RLed.write(ledState);
+ GLed.write(ledState);
+ //End dramatic effect
+
+
+ // read the state of the pushbutton value:
+ if(OKtoRead) {
+ for (i=0; i<NUMREL;i++){
+ buttonVal = capKeys[i].read();
+ wait_ms(DEBOUNCE);
+ buttonVal2 = capKeys[i].read();
+ buttonVal = buttonVal && buttonVal2;
+ if (buttonVal){
+ LCDMess(KEYHIT, LCDDELAY);
+ Relays[i].write(RELAY_ON);
+ capRST[i].write(LOW); //reset the cap key
+ pc.printf("i=%d Relays[i] = %d\n\r", i, Relays[i]);
+ millis.reset();
+ relayTimeout = RESET_DELAY;
+ OKtoRead = false;
+ break;
+ }
+ }
+ }//end OKtoRead
+
+ if (millis.read_ms() > relayTimeout) {
+ OKtoRead = true;
+ for (i=0; i<NUMREL; i++){
+ Relays[i].write(RELAY_OFF);
+ capRST[i].write(HIGH);
+
+ }
+ }
+ }// end forever while
+} // end main
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Oct 20 21:02:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file
