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: EthernetInterface IrcBot mbed-rtos mbed
Diff: main.cpp
- Revision:
- 0:e4e22c85b47f
- Child:
- 2:23c9ee69c999
diff -r 000000000000 -r e4e22c85b47f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Sep 20 09:46:48 2014 +0000 @@ -0,0 +1,41 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "IrcBot.h" + +#define NICKNAME "detonPHS" +//#define IRCSERVER "192.168.0.2" +#define IRCSERVER "10.254.166.45" +#define RINGNOTIFYCMD "PRIVMSG deton :@deton RING" +#define DEADTIME 10 // [sec] + +Serial pc(USBTX, USBRX); // tx, rx +AnalogIn ain(p17); +DigitalOut led(LED1); + +int main() { + EthernetInterface eth; + eth.init(); //Use DHCP + eth.connect(); + IrcBot irc(NICKNAME, IRCSERVER, 6667, NULL); + irc.connect(); + set_time(1408859241); // need for time(NULL), otherwise time(NULL) returns -1 + time_t prevOnTime = 0; + float f; + while (1){ + f = ain.read(); + pc.printf("%.2f,", f); + if (f > 0.3) { + led = 1; + time_t now = time(NULL); + //pc.printf("[%ld,%ld,%ld]", now, prevOnTime, now - prevOnTime); + if (now - prevOnTime > DEADTIME) { + irc.printfln("%s (%.2f)", RINGNOTIFYCMD, f); + prevOnTime = now; + } + } else { + led = 0; + } + irc.read(); + } +} +