Ross Gardiner / Mbed 2 deprecated PiballNeoController

Dependencies:   NeoStrip SerialDriver mbed-rtos mbed

Committer:
rossng
Date:
Sun Jan 31 01:25:59 2016 +0000
Revision:
2:868c8a43e4b7
Parent:
1:6feb61c0e4a1
Child:
3:d331c534064f
Enable Neopixels

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rossng 0:0513e7187b87 1 #include "mbed.h"
rossng 0:0513e7187b87 2 #include "SerialDriver.h"
rossng 2:868c8a43e4b7 3 #include "NeoStrip.h"
rossng 2:868c8a43e4b7 4 #include "gt.h"
rossng 0:0513e7187b87 5
rossng 2:868c8a43e4b7 6 #define N 64
rossng 2:868c8a43e4b7 7
rossng 1:6feb61c0e4a1 8 SerialDriver rpi(p9, p10);
rossng 1:6feb61c0e4a1 9 SerialDriver pc(USBTX, USBRX);
rossng 0:0513e7187b87 10 DigitalOut myled(LED1);
rossng 2:868c8a43e4b7 11 NeoStrip strip(p18, N);
rossng 0:0513e7187b87 12
rossng 0:0513e7187b87 13 int flash();
rossng 2:868c8a43e4b7 14 void set_pattern(NeoStrip strip);
rossng 0:0513e7187b87 15
rossng 2:868c8a43e4b7 16 int main() {
rossng 2:868c8a43e4b7 17 pc.printf("MBED: startup\n");
rossng 2:868c8a43e4b7 18
rossng 2:868c8a43e4b7 19 pattern(strip);
rossng 2:868c8a43e4b7 20
rossng 0:0513e7187b87 21 // setup serial port
rossng 1:6feb61c0e4a1 22 rpi.baud(115200);
rossng 0:0513e7187b87 23
rossng 0:0513e7187b87 24 char* line_buffer = (char*) malloc(100*sizeof(char));
rossng 0:0513e7187b87 25
rossng 1:6feb61c0e4a1 26 char c = rpi.getc();
rossng 0:0513e7187b87 27 int pos = 0;
rossng 0:0513e7187b87 28
rossng 0:0513e7187b87 29 while (c != '\n' && c != '\r') {
rossng 0:0513e7187b87 30 line_buffer[pos] = c;
rossng 1:6feb61c0e4a1 31 c = rpi.getc();
rossng 1:6feb61c0e4a1 32 pos++;
rossng 0:0513e7187b87 33 }
rossng 0:0513e7187b87 34
rossng 1:6feb61c0e4a1 35 line_buffer[pos] = '\0';
rossng 1:6feb61c0e4a1 36
rossng 1:6feb61c0e4a1 37 rpi.printf("ack\n");
rossng 0:0513e7187b87 38
rossng 0:0513e7187b87 39 int result = strcmp(line_buffer, "hello");
rossng 0:0513e7187b87 40
rossng 0:0513e7187b87 41 if (result == 0) {
rossng 2:868c8a43e4b7 42 set_pattern(strip);
rossng 1:6feb61c0e4a1 43 } else {
rossng 1:6feb61c0e4a1 44 pc.printf("Did not match.\n");
rossng 1:6feb61c0e4a1 45 pc.printf(line_buffer);
rossng 0:0513e7187b87 46 }
rossng 0:0513e7187b87 47 }
rossng 0:0513e7187b87 48
rossng 0:0513e7187b87 49
rossng 0:0513e7187b87 50 int flash() {
rossng 0:0513e7187b87 51 while(1) {
rossng 0:0513e7187b87 52 myled = 1;
rossng 0:0513e7187b87 53 wait(0.2);
rossng 0:0513e7187b87 54 myled = 0;
rossng 0:0513e7187b87 55 wait(0.2);
rossng 0:0513e7187b87 56 }
rossng 2:868c8a43e4b7 57 }
rossng 2:868c8a43e4b7 58
rossng 2:868c8a43e4b7 59 void set_pattern(NeoStrip strip) {
rossng 2:868c8a43e4b7 60 strip.setBrightness(0.2);
rossng 2:868c8a43e4b7 61 strip.setPixels(0, N, gt_img);
rossng 2:868c8a43e4b7 62 strip.write();
rossng 0:0513e7187b87 63 }