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.
Dependencies: 4DGL-uLCD-SE TextLCD mbed
Diff: main.cpp
- Revision:
- 0:dd375f44efef
- Child:
- 1:f531f70a27c3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Dec 07 06:54:24 2016 +0000
@@ -0,0 +1,77 @@
+#include "mbed.h"
+#include <mpr121.h>
+
+// on-board LEDs
+DigitalOut led1 ( LED1 ) ;
+DigitalOut led2 ( LED2 ) ;
+DigitalOut led3 ( LED3 ) ;
+DigitalOut led4 ( LED4 ) ;
+
+// COM port
+Serial com( USBTX , USBRX , 9600 );
+
+// keypad
+InterruptIn interrupt ( p26 ) ;
+I2C i2c ( p9 , p10 ) ;
+Mpr121 keypad ( & i2c , Mpr121::ADD_VSS ) ;
+
+int unsigned pin_count ( 0 ) ;
+int unsigned pin_value ( 0 ) ;
+void keypad_callback ( )
+{
+ // TEST
+ led2 = ! led2 ;
+// com.putc ( 'y' ) ;
+// com.putc ( 'z' ) ;
+// com.putc ( '\n' ) ;
+ int value ( keypad.read(0x00) ) ;
+ value += keypad.read(0x01) << 8 ;
+// com.printf( "%x\n" , value ) ;
+ if ( value == 0 ) return ;
+
+ switch ( value )
+ {
+// case 0 : return ;
+ case 0x1 : if ( pin_count != 0 ) -- pin_count ; pin_value /= 10 ; return ; // DELETE
+ case 0x10 : pin_value = pin_value * 10 ; break ; // 0
+ case 0x100 : pin_count = pin_value = 0 ; return ; // ENTER
+ case 0x2 : pin_value = pin_value * 10 + 1 ; break ;
+ case 0x20 : pin_value = pin_value * 10 + 2 ; break ;
+ case 0x200 : pin_value = pin_value * 10 + 3 ; break ;
+ case 0x4 : pin_value = pin_value * 10 + 4 ; break ;
+ case 0x40 : pin_value = pin_value * 10 + 5 ; break ;
+ case 0x400 : pin_value = pin_value * 10 + 6 ; break ;
+ case 0x8 : pin_value = pin_value * 10 + 7 ; break ;
+ case 0x80 : pin_value = pin_value * 10 + 8 ; break ;
+ case 0x800 : pin_value = pin_value * 10 + 9 ; break ;
+ }
+ if ( pin_count == 3 )
+ {
+// com.printf ( "{%d:%d}\n" , pin_value , pin_count ) ;
+ com.printf ( "%d\n\r" , pin_value ) ;
+ pin_value = pin_count = 0 ;
+ return ;
+// send pin
+// return ;
+ }
+// com.printf ( "%d : %d\n" , pin_value , pin_count ) ;
+ ++ pin_count ;
+// com.printf(8080) ;
+// int unsigned num = 8080 ;
+// com.write ( ) ;
+}
+
+int main ( )
+{
+ // INIT
+ interrupt.fall ( & keypad_callback ) ;
+ interrupt.mode ( PullUp ) ;
+
+ while(1)
+ {
+ led1 = 1;
+ wait(0.2);
+ led1 = 0;
+ wait(0.2);
+ }
+}