Serial communication with neXus Cidron reader to control light and buzzer

Dependencies:   Puck mbed

Files at this revision

API Documentation at this revision

Comitter:
serdtman
Date:
Fri Oct 23 12:43:11 2015 +0000
Commit message:
Cidron serial comunication

Changed in this revision

Puck.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Puck.lib	Fri Oct 23 12:43:11 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Nordic-Pucks/code/Puck/#5ac5f1d1a11e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 23 12:43:11 2015 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+
+DigitalOut led1(LED1);
+
+InterruptIn greenButton(BUTTON1);
+InterruptIn redButton(BUTTON2);
+InterruptIn beep1Button(BUTTON3);
+InterruptIn beep3Button(BUTTON4);
+
+Serial cidron(p9, p10);  // tx, rx
+
+uint8_t const GREEN[] = { 0xFF, 0x53, 0x00, 0x15, 0x00, 0x02, 0x69, 0x00, 0x00, 0x02, 0x0A, 0x00, 0x02, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15 };
+uint8_t const RED[] = { 0xFF, 0x53, 0x00, 0x15, 0x00, 0x02, 0x69, 0x00, 0x00, 0x02, 0x0A, 0x00, 0x01, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 };
+uint8_t const BUZZER_1_BEEP[] = { 0xFF, 0x53, 0x00, 0x0C, 0x00, 0x01, 0x6A, 0x00, 0x02, 0x01, 0x01, 0x01, 0x31 }; 
+uint8_t const BUZZER_3_BEEP[] = { 0xFF, 0x53, 0x00, 0x0C, 0x00, 0x01, 0x6A, 0x00, 0x02, 0x01, 0x01, 0x03, 0x2F };
+
+
+void write(Serial & serial, uint8_t const *data, uint16_t length) {
+    for (uint16_t i=0; i<length; i++) {
+        serial.putc(data[i]);
+    }
+}
+
+void greenButtonReleased(void){
+    write(cidron, GREEN, sizeof(GREEN));
+}
+
+void redButtonReleased(void){
+    write(cidron, RED, sizeof(RED));
+}
+
+void beep1ButtonReleased(void){
+    write(cidron, BUZZER_1_BEEP, sizeof(BUZZER_1_BEEP));
+}
+
+void beep3ButtonReleased(void){
+    write(cidron, BUZZER_3_BEEP, sizeof(BUZZER_3_BEEP));
+}
+
+int main() {
+    cidron.baud(9600);
+    
+    greenButton.rise(greenButtonReleased);
+    redButton.rise(redButtonReleased);
+    beep1Button.rise(beep1ButtonReleased);
+    beep3Button.rise(beep3ButtonReleased);
+    
+    while(1) {
+        led1 = !led1;
+        wait(1);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 23 12:43:11 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file