New classes were added to Event-Based Library for Arduino in your revision 45.
Versão em português desse artigo: Event-Based Library for Arduino atualizado para R45!.
Two new components are now available in this revision:
Properties
Persistent variables handler. Can be used to save configuration data to Arduino EEPROM persistent memory area.
In this example two boot counter variables are saved in EEPROM, one in numeric type and another in string type:
#include <Properties.h> #define PROPERTY_BOOTS 0 #define PROPERTY_TEXT 1 void setup() { Serial.begin(9600); if (Properties.load()) { if (Properties.getInt(PROPERTY_BOOTS)<=15) { //print data Serial.print("PROPERTY_BOOTS: "); Serial.println(Properties.getInt(PROPERTY_BOOTS)); Serial.print("PROPERTY_TEXT ("); Serial.print(Properties.get(PROPERTY_TEXT)->valueSize); Serial.print("): "); Serial.write((byte*)Properties.get(PROPERTY_TEXT)->value,Properties.get(PROPERTY_TEXT)->valueSize); Serial.println(); //sum PROPERTY_BOOTS and update text Properties.set(PROPERTY_BOOTS,Properties.getInt(PROPERTY_BOOTS)+1); char* text = (char*)malloc(32); sprintf(text,"Boot times: %d...", Properties.getInt(PROPERTY_BOOTS)); Properties.set(PROPERTY_TEXT,(void*)text,strlen(text)); Properties.save(); } else { Serial.println("Flushing!"); //flush data Properties.flush(); Properties.save(); } } else { Serial.println("Starting!"); //create data Properties.set(PROPERTY_BOOTS,1); char* text = (char*)malloc(32); sprintf(text,"Boot times: %d...", Properties.getInt(PROPERTY_BOOTS)); Properties.set(PROPERTY_TEXT,(void*)text,strlen(text)); Properties.save(); } } void loop() { }
TimedEvent
Simple task scheduler.
In this example one event (event1) is used to control when the another one (event2) is started and stopped at regular intervals while they send data through Serial Monitor:
#include <TimedEvent.h> #define CONTROLLED_TIMER 1 bool flag = true; void setup() { Serial.begin(9600); //event 1 TimedEvent.addTimer(5000, event1); //event 2 TimedEvent.addTimer(CONTROLLED_TIMER, 500, event2); TimedEvent.start(CONTROLLED_TIMER); } void loop() { TimedEvent.loop(); } void event1(TimerInformation* Sender) { Serial.print("event1: "); if (flag=!flag) { TimedEvent.start(CONTROLLED_TIMER); Serial.println("START!"); } else { TimedEvent.stop(CONTROLLED_TIMER); Serial.println("STOP!"); } } void event2(TimerInformation* Sender) { Serial.println("event2!!"); }
This project has their own repository with more information about the classes, usage instructions and download options. It could be accessed through the URL http://code.google.com/p/ebl-arduino/.
No comments:
Post a Comment