Skip to content

Instantly share code, notes, and snippets.

@Wesitos
Created November 18, 2015 20:15
Show Gist options
  • Save Wesitos/7486c306bed7f2abe368 to your computer and use it in GitHub Desktop.
Save Wesitos/7486c306bed7f2abe368 to your computer and use it in GitHub Desktop.
Laboratorio 15 y 16
byte pin_list[] = {9,10,11,12};
byte input_pin = 5;
unsigned counter = 0;
long int last_time = 0;
void setup(){
for (int i=0; i < sizeof(pin_list); i++)
pinMode(pin_list[i], OUTPUT);
digitalWrite(input_pin, HIGH);
last_time = millis();
Serial.begin(9600);
}
void paso(int n){
for (int i=0; i<4; i++)
digitalWrite(pin_list[i], (i == n)?LOW:HIGH);
}
void loop(){
int val = analogRead(input_pin);
long unsigned time = millis();
if(val!=512 & last_time + 5E4/abs(val - 512) < time){
last_time = time;
paso((val > 512?counter++:counter--)%sizeof(pin_list));
Serial.println(val);
}
}
byte pin_list[] = {9,10,11,12};
int input_pin = 8;
unsigned counter = 0;
volatile boolean creciente = true;
long int last_time = 0;
void setup(){
for (int i=0; i < sizeof(pin_list); i++)
pinMode(pin_list[i], OUTPUT);
digitalWrite(input_pin, HIGH);
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), button_press, FALLING);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void button_press(){
creciente = !creciente;
digitalWrite(13, creciente);
}
void paso(int n){
for (int i=0; i<4; i++)
digitalWrite(pin_list[i], (i == n)?LOW:HIGH);
}
void loop(){
paso((creciente?counter++:counter--)%sizeof(pin_list));
delay(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment