Skip to content

Instantly share code, notes, and snippets.

@Bluebie
Created September 28, 2010 01:38
Show Gist options
  • Save Bluebie/600244 to your computer and use it in GitHub Desktop.
Save Bluebie/600244 to your computer and use it in GitHub Desktop.
// -=- Angular Deplexer -=-
// A little chip to take multiplexed PPM
// signals, and split them up over the
// digital pins, for RC things, and
// fun little cassette tape robots!
// <3 Bluebie
// And now for some settings...
const byte input = 0; // Which analog input should I use?
const byte outputs = 10; // How many outputs maximum?
const byte first_output = 2; // and which pin should be our first?
const int threshold = 170; // How many millivolts are required on input to be HIGH / 5?
const byte postgap = 5; // msec duration
// Just a few little variables to keep our head on straight...
byte iter = 0;
byte output_lines[outputs];
int light = LOW;
void setup() {
// make a nice little array to lookup our output pins with - feel free to rearrange them!
for (iter = 0; iter < outputs; iter++) {
output_lines[iter] = first_output + iter;
pinMode(output_lines[iter], OUTPUT);
}
pinMode(13, OUTPUT);
digitalWrite(13, light);
}
int reading = 0;
int currently = LOW;
int appears = LOW;
byte output = 0;
// gaps
unsigned long previous_high = 0;
unsigned long now = 0;
void loop() {
reading = analogRead(input);
appears = reading > threshold ? HIGH : LOW;
if (currently != appears) {
// check for gap, and reset as needed
now = millis();
if (appears == HIGH && (now - previous_high) > postgap) {
output = 0;
light = light == LOW ? HIGH : LOW;
digitalWrite(13, light);
}
digitalWrite(output_lines[output], appears);
currently = appears;
if (currently == LOW) {
output++;
if (output >= outputs) output = 0;
} else { // quickly note down the times for gap finding...
previous_high = millis();
}
}
}
void set_servo(byte num) {
output = num;
if (output == outputs) output = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment