Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#define PUERTO_LEDS PORTD #define CONFIGURAR_LEDS DDRD = 0xFF #define CONFIGURAR_BOTON DDRB = DDRB | (1<<0) #define BOT_PRESIONADO digitalRead(8) #define CONFIGURAR_LED_TEST DDRB = DDRB | (1<<5) #define ENCENDER_LED_TEST PORTB = PORTB | (1<<5) #define APAGAR_LED_TEST PORTB = PORTB & ~(1<<5) #define TPO_LED_TEST_ON 950 #define TPO_LED_TEST_OFF 50 //Estado anterior del boton static bool presionado_ant = 0; //referencia milis led test static unsigned long milis_ant_test = 0; // static bool led_ant_test = 0; static int efecto = 0; static unsigned long milis_ant_efecto = 0; static int contador = 0; int start_presion = 0; int end_presion = 0; int idle_presion = 0; int hold_presion = 0; bool sentido_efecto1 = 0; void setup() { CONFIGURAR_LED_TEST; CONFIGURAR_BOTON; CONFIGURAR_LEDS; } void loop() { LedTest(); SupervisaPulsador(); Efectos(); } void SupervisaPulsador(void) { bool presionado = BOT_PRESIONADO; if (presionado == presionado_ant) return; presionado_ant = presionado; if (BOT_PRESIONADO) { start_presion = millis(); idle_presion = start_presion - end_presion; /*efecto++; PUERTO_LEDS = B00000000; if(efecto == 3){ efecto = 0; }*/ } else { end_presion = millis(); hold_presion = end_presion - start_presion; if (hold_presion >= 500) { efecto = 2; } if (hold_presion < 500) efecto = 0; if (idle_presion < 500) { efecto = 1; sentido_efecto1 = !sentido_efecto1; } } } /* Eventos Se presionó el botón Se superaron los 500ms con el botón presionado Se liberó el botón antes de los 500ms Se liberó el botón después de los 500ms Pasaron más de 500ms desde que se liberó el botón */ void LedTest() { unsigned long tiempoActual = millis(); if (tiempoActual - milis_ant_test >= 950 && led_ant_test == 0) { milis_ant_test = tiempoActual; ENCENDER_LED_TEST; led_ant_test = 1; } else if (tiempoActual - milis_ant_test >= 50 && led_ant_test == 1) { milis_ant_test = tiempoActual; APAGAR_LED_TEST; led_ant_test = 0; } } void Efectos(void) { unsigned long tiempoActualEfecto = millis(); if (tiempoActualEfecto - milis_ant_efecto >= 500) { milis_ant_efecto = tiempoActualEfecto; switch (efecto) { case 0: PUERTO_LEDS <<= 1; PUERTO_LEDS = PUERTO_LEDS | 1; if (PUERTO_LEDS == B11111111) { PUERTO_LEDS = B00000000; } break; case 1: if (sentido_efecto1) { switch (contador) { case 0: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 0); break; case 1: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 1); break; case 2: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 2); break; case 3: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 3); break; case 4: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 4); break; case 5: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 5); break; case 6: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 6); break; case 7: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 7); break; } contador++; if (contador > 7) contador = 0; } else { switch (contador) { case 0: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 7); break; case 1: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 6); break; case 2: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 5); break; case 3: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 4); break; case 4: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 3); break; case 5: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 2); break; case 6: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 1); break; case 7: PUERTO_LEDS = B00000000; PUERTO_LEDS = PUERTO_LEDS | (1 << 0); break; } contador++; if (contador > 7) contador = 0; } break; case 2: PUERTO_LEDS = B00000000; default: break; } } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)