Created
December 16, 2010 18:26
-
-
Save Kobold/743771 to your computer and use it in GitHub Desktop.
An arduino control thingy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the pins for each connector on the el escudo | |
#define A 2 | |
#define B 3 | |
#define C 4 | |
#define D 5 | |
#define E 6 | |
#define F 7 | |
#define G 8 | |
#define H 9 | |
int currentGroup = 0; | |
int seconds = 2; | |
int sensorPin = 12; | |
// turn the given channel on | |
void el_on(int channel) | |
{ | |
pinMode(channel, OUTPUT); | |
digitalWrite(channel, LOW); | |
} | |
// turn the given channel off | |
void el_off(int channel) | |
{ | |
pinMode(channel, INPUT); | |
digitalWrite(channel, HIGH); | |
} | |
void el_apply(int group, void (*func)(int)) | |
{ | |
switch (group) { | |
case 0: | |
func(A); | |
break; | |
case 1: | |
func(B); | |
func(C); | |
break; | |
case 2: | |
func(D); | |
func(E); | |
break; | |
case 3: | |
func(F); | |
break; | |
} | |
} | |
void setup() | |
{ | |
el_off(A); | |
el_off(B); | |
el_off(C); | |
el_off(D); | |
el_off(E); | |
el_off(F); | |
} | |
void loop() | |
{ | |
// detect the pulse | |
unsigned long dur = pulseIn(sensorPin, HIGH, seconds * 1000000); | |
el_apply(currentGroup, el_on); | |
delay(150); | |
el_apply(currentGroup, el_off); | |
currentGroup = (currentGroup + 1) % 4; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment