test fork

Dependencies:   C12832

Fork of seoul-iot-hackathon-demo by Seoul IoT Hackathon Admins

Committer:
kcod
Date:
Sat Nov 04 07:12:21 2017 +0000
Revision:
10:911c7a95308e
Parent:
0:6b7ffde9f287
test commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sarahmarshy 0:6b7ffde9f287 1 //----------------------------------------------------------------------------
sarahmarshy 0:6b7ffde9f287 2 // The confidential and proprietary information contained in this file may
sarahmarshy 0:6b7ffde9f287 3 // only be used by a person authorised under and to the extent permitted
sarahmarshy 0:6b7ffde9f287 4 // by a subsisting licensing agreement from ARM Limited or its affiliates.
sarahmarshy 0:6b7ffde9f287 5 //
sarahmarshy 0:6b7ffde9f287 6 // (C) COPYRIGHT 2016 ARM Limited or its affiliates.
sarahmarshy 0:6b7ffde9f287 7 // ALL RIGHTS RESERVED
sarahmarshy 0:6b7ffde9f287 8 //
sarahmarshy 0:6b7ffde9f287 9 // This entire notice must be reproduced on all copies of this file
sarahmarshy 0:6b7ffde9f287 10 // and copies of this file may only be made by a person if such person is
sarahmarshy 0:6b7ffde9f287 11 // permitted to do so under the terms of a subsisting license agreement
sarahmarshy 0:6b7ffde9f287 12 // from ARM Limited or its affiliates.
sarahmarshy 0:6b7ffde9f287 13 //----------------------------------------------------------------------------
sarahmarshy 0:6b7ffde9f287 14
sarahmarshy 0:6b7ffde9f287 15 #include "mbed.h"
sarahmarshy 0:6b7ffde9f287 16 #include "C12832.h"
sarahmarshy 0:6b7ffde9f287 17
kcod 10:911c7a95308e 18
sarahmarshy 0:6b7ffde9f287 19 // GLOBAL VARIABLES HERE
kcod 10:911c7a95308e 20 C12832 lcd(D11, D13, D6, D7, D10);
kcod 10:911c7a95308e 21
kcod 10:911c7a95308e 22 DigitalOut led(D9, 1);
kcod 10:911c7a95308e 23 DigitalIn button(BUTTON, PullUp);
kcod 10:911c7a95308e 24
kcod 10:911c7a95308e 25
kcod 10:911c7a95308e 26 AnalogIn pot1(A0);
kcod 10:911c7a95308e 27 EventQueue queue;
kcod 10:911c7a95308e 28
sarahmarshy 0:6b7ffde9f287 29
sarahmarshy 0:6b7ffde9f287 30 // FUNCTION DEFINITIONS HERE
kcod 10:911c7a95308e 31 void lcd_print(const char* message) {
kcod 10:911c7a95308e 32 lcd.cls();
kcod 10:911c7a95308e 33 lcd.locate(0,3);
kcod 10:911c7a95308e 34 lcd.printf(message);
kcod 10:911c7a95308e 35 }
sarahmarshy 0:6b7ffde9f287 36
kcod 10:911c7a95308e 37 void read_potentiometer() {
kcod 10:911c7a95308e 38 static float potentiometer_val = 0;
kcod 10:911c7a95308e 39 if ((float)pot1 != potentiometer_val) {
kcod 10:911c7a95308e 40 potentiometer_val = (float)pot1;
kcod 10:911c7a95308e 41 char val[13];
kcod 10:911c7a95308e 42 sprintf(val, "%.2f", potentiometer_val);
kcod 10:911c7a95308e 43 lcd_print(val);
kcod 10:911c7a95308e 44 }
kcod 10:911c7a95308e 45 }
kcod 10:911c7a95308e 46
kcod 10:911c7a95308e 47 void blink_led() {
kcod 10:911c7a95308e 48 led = !led;
kcod 10:911c7a95308e 49 }
kcod 10:911c7a95308e 50
kcod 10:911c7a95308e 51 void set_blink_led() {
kcod 10:911c7a95308e 52 static int blink_id = NULL;
kcod 10:911c7a95308e 53 // Read the button
kcod 10:911c7a95308e 54 int blink = !button.read();
kcod 10:911c7a95308e 55 // If the button is pressed and the light is not currently blinking
kcod 10:911c7a95308e 56 if (blink == 1 && blink_id == NULL) {
kcod 10:911c7a95308e 57 // Add blinking the LED to event queue
kcod 10:911c7a95308e 58 blink_id = queue.call_every(500, blink_led);
kcod 10:911c7a95308e 59 }
kcod 10:911c7a95308e 60 else if (blink == 0) {
kcod 10:911c7a95308e 61 // Cancel the blinking event
kcod 10:911c7a95308e 62 queue.cancel(blink_id);
kcod 10:911c7a95308e 63 blink_id = NULL;
kcod 10:911c7a95308e 64 led = 1;
kcod 10:911c7a95308e 65 }
kcod 10:911c7a95308e 66 }
sarahmarshy 0:6b7ffde9f287 67 int main()
sarahmarshy 0:6b7ffde9f287 68 {
sarahmarshy 0:6b7ffde9f287 69 // MAIN CODE HERE
kcod 10:911c7a95308e 70 lcd_print("Hello World!");
kcod 10:911c7a95308e 71
kcod 10:911c7a95308e 72 queue.call_every(100, read_potentiometer);
kcod 10:911c7a95308e 73 while(1){
kcod 10:911c7a95308e 74 wait_ms(100);
kcod 10:911c7a95308e 75 queue.dispatch(0);
kcod 10:911c7a95308e 76 }
kcod 10:911c7a95308e 77
kcod 10:911c7a95308e 78 queue.call_every(100, set_blink_led);
sarahmarshy 0:6b7ffde9f287 79 }
kcod 10:911c7a95308e 80