Arduino http://concurrency.cc – Plumbing for the Arduino

http://concurrency.cc/docs/ Plumbing for the Arduino
http://concurrency.cc/download.html

// try to parallel processing on arduino like plumbing
// plumbing is more elegant,
// but its possible to do basic stuff without plumping on arduino using Alarms/Timer libs
// http://concurrency.cc/download.html

breadboard setup

in this basic example,
three LEDs are blinking..
with different on/off times,
and one button,
pushed all LEDs will be switch on


#include <Time.h>
#include <TimeAlarms.h>

// try to parallel processing on arduino like plumbing
// plumbing is more elegant,
// but its possible to do basic stuff without plumping on arduino using Alarms/Timer libs
// http://concurrency.cc/download.html

//AlarmId Alarm_A = Alarm.timerRepeat(start_every_seconds, func_name );
//AlarmId Alarm_A = Alarm.timerOnce(start_in_seconds, func_name );
//Alarm.disable(Alarm_A);
//Alarm.delay(10);

const int PinA = 8;
const int PinB = 7;
const int PinC = 13;
const int ButtonPin = 6;

int mem_A0 = 0;// memory var A0
int mem_B0 = 0;// memory var B0
int mem_C0 = 0;// memory var C0

AlarmId Alarm_A_on = Alarm.timerOnce(2, A_high ); // would be nice to have: callbacks with args, but without, i try to do something with global vars
AlarmId Alarm_B_on = Alarm.timerOnce(3, B_high );
AlarmId Alarm_C_on = Alarm.timerOnce(4, C_high );

void setup() {

Serial.begin(9600);
// initialize the digital pin as an output.
pinMode(PinA, OUTPUT);
pinMode(PinB, OUTPUT);
pinMode(PinC, OUTPUT);

pinMode(ButtonPin, INPUT); // button
digitalWrite(ButtonPin, HIGH); // use internal pull-up resistor, and button with only one cable without resistor
}

void loop() {
Alarm.delay(1); // time frame segmentation

int BUTTON_STATE = digitalRead(ButtonPin);// check every ms, for best response
if (BUTTON_STATE == LOW){
digitalWrite(PinA, HIGH);
digitalWrite(PinB, HIGH);
digitalWrite(PinC, HIGH);
}
}

void A_high(){
digitalWrite(PinA, HIGH); // set the LED on
AlarmId Alarm_A_off = Alarm.timerOnce(2, A_low );
Serial.print("mem_A0: ");Serial.println( mem_A0 );
mem_A0 = mem_A0+1;
}
void A_low(){
digitalWrite(PinA, LOW); // set the LED on
AlarmId Alarm_A_on = Alarm.timerOnce(2, A_high );
}

void B_high(){
digitalWrite(PinB, HIGH); // set the LED on
AlarmId Alarm_B_off = Alarm.timerOnce(3, B_low );
Serial.print("mem_B0: ");Serial.println( mem_B0 );
mem_B0 = mem_B0+1;
}
void B_low(){
digitalWrite(PinB, LOW); // set the LED on
AlarmId Alarm_B_on = Alarm.timerOnce(3, B_high );
}

void C_high(){
digitalWrite(PinC, HIGH); // set the LED on
AlarmId Alarm_C_off = Alarm.timerOnce(4, C_low );
Serial.print("mem_C0: ");Serial.println( mem_C0 );
mem_C0 = mem_C0+1;
}
void C_low(){
digitalWrite(PinC, LOW); // set the LED on
AlarmId Alarm_C_on = Alarm.timerOnce(3, C_high );
}

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.