Luz Para Bicicleta Con Pic18F4550
int led1 = 0;
int led2 = 1;
int led3 = 2;
int led4 = 3;
int led5 = 4;
int val; // variable forreading the pin status
int val2; // variable for reading the delayed status
int estado_del_boton; // variable to hold the button state
int luz = 0; //What mode is the light in?
void setup() {
pinMode(boton, INPUT); // Set the switch pin as input
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5, OUTPUT);
Serial.begin(9600); // Set up serial communication at 9600bps
estado_del_boton = digitalRead(boton); // read the initial state
}
voidloop(){
val = digitalRead(boton); // lee el valor de entrada y lo guarda en val
delay(100); // 10 milliseconds is a good amount of time
val2 = digitalRead(boton);// lee la entrada otravez y chequea las repeticiones
if (val == val2) { // asegura que tenemos 2 constantes leidas!
if (val != estado_del_boton) { // el estado delboton ha cambiado!
if (val == LOW) { //chequea si el boton esa apretado
if (luz == 0) { // si esta apagado
luz = 1; // enciende lasluces!
} else {
if (luz == 1) { // si esta todo encendido
luz = 2; // hace parpadear!
} else {
if (luz == 2) { // si estaparpadeando
luz = 3; // hace ola!
} else {
if (luz == 3) { // si esta hacendo ola,
luz = 4; // hace mio!
}else {if (luz == 4) { // si esta hacendo mio,
luz = 5; // hace mio2!
}else {
if (luz == 5) { // si esta hacendo mio2,
luz = 0;...
Regístrate para leer el documento completo.