Example program for the SeeedStudio Grove Shield V2.0, based on multiple grove components. This program uses Grove Digit Display on UART, Grove Relay on D4, Grove LED Bar on D5, Grove Light Sensor on A0 and Grove Potentiometer (Rotary Angle Sensor) on A3.

Dependencies:   DigitDisplay LED_Bar mbed

Committer:
screamer
Date:
Wed Jul 30 13:17:22 2014 +0000
Revision:
0:8c6756332bd8
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:8c6756332bd8 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
screamer 0:8c6756332bd8 2 *
screamer 0:8c6756332bd8 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
screamer 0:8c6756332bd8 4 * and associated documentation files (the "Software"), to deal in the Software without
screamer 0:8c6756332bd8 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
screamer 0:8c6756332bd8 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
screamer 0:8c6756332bd8 7 * Software is furnished to do so, subject to the following conditions:
screamer 0:8c6756332bd8 8 *
screamer 0:8c6756332bd8 9 * The above copyright notice and this permission notice shall be included in all copies or
screamer 0:8c6756332bd8 10 * substantial portions of the Software.
screamer 0:8c6756332bd8 11 *
screamer 0:8c6756332bd8 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
screamer 0:8c6756332bd8 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
screamer 0:8c6756332bd8 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
screamer 0:8c6756332bd8 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
screamer 0:8c6756332bd8 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
screamer 0:8c6756332bd8 17 */
screamer 0:8c6756332bd8 18
screamer 0:8c6756332bd8 19 #include "mbed.h"
screamer 0:8c6756332bd8 20 #include "LED_Bar.h"
screamer 0:8c6756332bd8 21 #include "DigitDisplay.h"
screamer 0:8c6756332bd8 22
screamer 0:8c6756332bd8 23 /**
screamer 0:8c6756332bd8 24 * RX pin - D0
screamer 0:8c6756332bd8 25 * TX pin - D1
screamer 0:8c6756332bd8 26 */
screamer 0:8c6756332bd8 27 DigitDisplay display(D0, D1);
screamer 0:8c6756332bd8 28 LED_Bar bar(D6, D5);
screamer 0:8c6756332bd8 29 DigitalOut relay(D4);
screamer 0:8c6756332bd8 30
screamer 0:8c6756332bd8 31 AnalogIn lsensor(A0);
screamer 0:8c6756332bd8 32 AnalogIn pot(A3);
screamer 0:8c6756332bd8 33
screamer 0:8c6756332bd8 34 DigitalOut myled(LED1);
screamer 0:8c6756332bd8 35
screamer 0:8c6756332bd8 36 int main() {
screamer 0:8c6756332bd8 37 float val;
screamer 0:8c6756332bd8 38 uint8_t array[4];
screamer 0:8c6756332bd8 39 int valnum = 1234;
screamer 0:8c6756332bd8 40
screamer 0:8c6756332bd8 41 // test bar and display first
screamer 0:8c6756332bd8 42 bar.setLevel(0);
screamer 0:8c6756332bd8 43 display.clear();
screamer 0:8c6756332bd8 44 for (int i=0; i<4; i++) {
screamer 0:8c6756332bd8 45 for (int j=0; j<10; j++) {
screamer 0:8c6756332bd8 46 bar.setLevel(j);
screamer 0:8c6756332bd8 47 for (int z=4; z>=3-i; z--) {
screamer 0:8c6756332bd8 48 display.write(z, j);
screamer 0:8c6756332bd8 49 };
screamer 0:8c6756332bd8 50 wait(0.05);
screamer 0:8c6756332bd8 51 relay = !relay;
screamer 0:8c6756332bd8 52 }
screamer 0:8c6756332bd8 53 }
screamer 0:8c6756332bd8 54
screamer 0:8c6756332bd8 55 bar.setLevel(0);
screamer 0:8c6756332bd8 56 display.clear();
screamer 0:8c6756332bd8 57 while(1) {
screamer 0:8c6756332bd8 58 // read the sensor data
screamer 0:8c6756332bd8 59 val = lsensor.read();
screamer 0:8c6756332bd8 60
screamer 0:8c6756332bd8 61 // set bar
screamer 0:8c6756332bd8 62 bar.setLevel((int)(val * 10));
screamer 0:8c6756332bd8 63
screamer 0:8c6756332bd8 64 // set display
screamer 0:8c6756332bd8 65 valnum = (int)(val * 1000);
screamer 0:8c6756332bd8 66 for (int i=3; i>=0; i--) {
screamer 0:8c6756332bd8 67 array[i] = valnum % 10;
screamer 0:8c6756332bd8 68 valnum /= 10;
screamer 0:8c6756332bd8 69 }
screamer 0:8c6756332bd8 70 display.write(array);
screamer 0:8c6756332bd8 71
screamer 0:8c6756332bd8 72 // set relay
screamer 0:8c6756332bd8 73 relay = val <= pot ? 1 : 0;
screamer 0:8c6756332bd8 74
screamer 0:8c6756332bd8 75 // set LED
screamer 0:8c6756332bd8 76 myled = !myled;
screamer 0:8c6756332bd8 77
screamer 0:8c6756332bd8 78 wait(0.1);
screamer 0:8c6756332bd8 79 }
screamer 0:8c6756332bd8 80 }