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: SwAnalog_LPC1768 mbed
Fork of SwAnalogInputLibraryExampleProgram by
Diff: main.cpp
- Revision:
- 0:7ce3de2c24c3
- Child:
- 1:c4d2d6df69ce
diff -r 000000000000 -r 7ce3de2c24c3 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Feb 12 00:52:09 2012 +0000 @@ -0,0 +1,61 @@ +//******************************************************************** +// SwAnalogInput Library example program +// mbed no analog port de 3hon no sw wo ninsiki suru. +// 6hon no analog port (p15 - p20) de 6 * 3 = 18 ko no sw ninsiki ga dekiru. +// +// <schematic> +// -.- mbed VOUT(+3.3[V]) +// | |--------------------> mbed p20(ADinput) +// | --------- --------- --------- | --------- +// .---| Rsw2 |---.---| Rsw1 |---.---| Rsw0 |---.---| Rout |----| +// | --------- | --------- | --------- | --------- | +// | ---- | ----- | ----- | | +// |-----o o------.-----o o------.-----o o------| ----- +// SW2 SW1 SW0 mbed GND(0[V]) +// +// Rsw2 : 8.2[kohm], Rsw1 = 3.9[kohm], Rsw0 = 2.0[kohm], Rout = 1.0[kohm] (R no seido ha +-1[%]) +// +// <program no naiyo> +// mbed LED1 : sw0 no level de tento sw Off = led Off, sw On = led On +// mbed LED2 : sw1 no level de tento sw Off = led Off, sw On = led On +// mbed LED3 : sw2 no level de tento sw Off = led Off, sw On = led On +// mbed LED4 : sw0,sw1,sw2 no Off kara On henka de led tento jotai wo hanten. +// +// +// <rireki> +// 2012/02/12 : syohan +// ********************************************************************* + +#include "mbed.h" +#include "SwAnalog.h" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +SwAnalog sw(p20); // p20(adinput) :sw0,sw1,sw2 + +int main() { + while(1) { + // sw level and edge data refresh + sw.refreshEdgeData(); + + // tact action (sw0 level = on : led1 = on) + led1 = sw.checkLevel(0); + + // tact action (sw1 level = off : led2 = on) + led2 = sw.checkLevel(1); + + // tact action (sw2 level = off : led3 = on) + led3 = sw.checkLevel(2); + + // toggle action (sw0 to sw3 level Off to On : led4 invert ) + if((sw.checkEdgeOn(0) == 1) // sw0 + || (sw.checkEdgeOn(1) == 1) // sw1 + || (sw.checkEdgeOn(2) == 1) // sw2 + ){ + led4 = !led4; + } + } +}