Lets merge mbed with arduino. Basic arduino programming code for the Nucleo platform. Note: the code is not efficient, just take the idea.
Revision 0:312d60e4b87d, committed 2014-09-13
- Comitter:
- jose_23991
- Date:
- Sat Sep 13 12:47:56 2014 +0000
- Commit message:
- Version 1.0
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 312d60e4b87d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Sep 13 12:47:56 2014 +0000 @@ -0,0 +1,93 @@ +#include "mbed.h" + +/***************************************/ + +#define INPUT 0 +#define OUTPUT 1 +#define INPUT_PULLUP 2 +#define LOW 0 +#define HIGH 1 + +/***************************************/ + +void setup(); +void loop(); +void pinMode(PinName pin, int mode); +void digitalWrite(PinName pin, int value); +int digitalRead(PinName pin); +void delay(unsigned long t); + +/***************************************/ + +int main() +{ + setup(); + while(1) + { + loop(); + } +} + +/***************************************/ + +// Type PinName is declared in mbed library +PinName button = USER_BUTTON; +PinName led = LED1; + +/***************************************/ + +void setup() +{ + pinMode(button, INPUT_PULLUP); // Set button as input with internall pull-up + pinMode(led, OUTPUT); // Set led as output + digitalWrite(led, LOW); // Set led off +} + +void loop() +{ + // Basic digitalRead + if(digitalRead(button) == LOW) + { + digitalWrite(led, HIGH); + delay(200); + } + else + digitalWrite(led, LOW); + + /* + // Basic blink + digitalWrite(led, HIGH); + delay(1000); + digitalWrite(led, LOW); + delay(1000); + */ +} + +/***************************************/ + +void pinMode(PinName pin, int mode) +{ + if(mode == INPUT) + DigitalIn pm(pin); + else if(mode == INPUT_PULLUP) + DigitalIn pm(pin, PullUp); + else if(mode == OUTPUT) + DigitalOut pm(pin); +} + +void digitalWrite(PinName pin, int value) +{ + DigitalOut dw(pin, value); +} + +int digitalRead(PinName pin) +{ + DigitalIn dr(pin); + + return dr.read(); +} + +void delay(unsigned long t) +{ + wait_ms(t); +}
diff -r 000000000000 -r 312d60e4b87d mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Sep 13 12:47:56 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file