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: DigitDisplay LED_Bar mbed
main.cpp
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #include "mbed.h" 00020 #include "LED_Bar.h" 00021 #include "DigitDisplay.h" 00022 00023 /** 00024 * RX pin - D0 00025 * TX pin - D1 00026 */ 00027 DigitDisplay display(D0, D1); 00028 LED_Bar bar(D6, D5); 00029 DigitalOut relay(D4); 00030 00031 AnalogIn lsensor(A0); 00032 AnalogIn pot(A3); 00033 00034 DigitalOut myled(LED1); 00035 00036 int main() { 00037 float val; 00038 uint8_t array[4]; 00039 int valnum = 1234; 00040 00041 // test bar and display first 00042 bar.setLevel(0); 00043 display.clear(); 00044 for (int i=0; i<4; i++) { 00045 for (int j=0; j<10; j++) { 00046 bar.setLevel(j); 00047 for (int z=4; z>=3-i; z--) { 00048 display.write(z, j); 00049 }; 00050 wait(0.05); 00051 relay = !relay; 00052 } 00053 } 00054 00055 bar.setLevel(0); 00056 display.clear(); 00057 while(1) { 00058 // read the sensor data 00059 val = lsensor.read(); 00060 00061 // set bar 00062 bar.setLevel((int)(val * 10)); 00063 00064 // set display 00065 valnum = (int)(val * 1000); 00066 for (int i=3; i>=0; i--) { 00067 array[i] = valnum % 10; 00068 valnum /= 10; 00069 } 00070 display.write(array); 00071 00072 // set relay 00073 relay = val <= pot ? 1 : 0; 00074 00075 // set LED 00076 myled = !myled; 00077 00078 wait(0.1); 00079 } 00080 }
Generated on Tue Jul 12 2022 14:29:10 by
1.7.2
Grove Shield V2