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.
Diff: arduino.c
- Revision:
- 0:a2d36977aec3
diff -r 000000000000 -r a2d36977aec3 arduino.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arduino.c Sun Aug 05 12:47:00 2012 +0000 @@ -0,0 +1,55 @@ +#include "arduino.h" + +long time_counter; +Ticker ticker; + +long millis(void) { + return time_counter/1000; +} +long micros(void) { + return time_counter; +} + +void one_micro(void) { + time_counter += 10; +} + +void arduino_setup(void) { + ticker.attach_us( &one_micro, 10 ); +} + +byte lowByte(short int low) { + byte bytelow = 0; + bytelow = (low & 0xFF); + return bytelow; +} + +byte highByte(short int high) { + byte bytehigh = 0; + bytehigh = ((high >> 8) & 0xFF); + return bytehigh; +} + +long random(int number) { + return (rand()%number); +} + +int random(int numberone, int numbertwo) { + int random = 0; + if ((numberone < 0) && (numbertwo < 0)) { + numberone = numberone * -1; + numbertwo = numbertwo * -1; + random = -1 * (rand()%(numberone + numbertwo)); + } + if ((numbertwo < 0) && (numberone >= 0)) { + numbertwo = numbertwo * -1; + random = (rand()%(numberone + numbertwo)) - numbertwo; + } + if ((numberone < 0) && (numbertwo >= 0)) { + numberone = numberone * -1; + random = (rand()%(numberone + numbertwo)) - numberone; + } else { + random = (rand()%(numberone + numbertwo)) - min(numberone, numbertwo); + } + return random; +}