--- /dev/null
+void setup() {
+ // put your setup code here, to run once:
+ DDRB |= (1 << PB5);
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+ PORTB |= (1 << PB5);
+ _delay_ms(500);
+ PORTB &= ~(1 << PB5);
+ _delay_ms(500);
+}
--- /dev/null
+#include <Adafruit_NeoPixel.h>
+#define NUM_PIXELS 10
+#define PIN 5
+Adafruit_NeoPixel strip(NUM_PIXELS, PIN, NEO_GRB);
+
+#define BTN_LEFT 3
+#define BTN_RIGHT 2
+
+volatile uint8_t position = 0;
+
+void L_button_pressed_ISR();
+void R_button_pressed_ISR();
+
+void setup() {
+ pinMode(BTN_LEFT, INPUT_PULLUP);
+ pinMode(BTN_RIGHT, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(BTN_LEFT), L_button_pressed_ISR, FALLING);
+ attachInterrupt(digitalPinToInterrupt(BTN_RIGHT), R_button_pressed_ISR, RISING);
+
+ pinMode(PIN, OUTPUT);
+ strip.begin();
+}
+
+void L_button_pressed_ISR() {
+ if (position > 0) position--;
+}
+
+void R_button_pressed_ISR() {
+ if (position < (NUM_PIXELS - 1)) position++;
+}
+
+void loop() {
+ for (int i = 0 ; i < NUM_PIXELS; i++)
+ {
+ if (i == position)
+ {
+ strip.setPixelColor(i, strip.Color(255, 0, 0));
+ }
+ else
+ {
+ strip.setPixelColor(i, strip.Color(0, 0, 255));
+ }
+ }
+ strip.show();
+}
--- /dev/null
+#include <Adafruit_NeoPixel.h>
+#define NUM_PIXELS 10
+#define PIN 5
+Adafruit_NeoPixel strip(NUM_PIXELS, PIN, NEO_GRB);
+
+#define BTN_LEFT 3
+#define BTN_RIGHT 2
+
+uint8_t position = 0;
+
+void setup() {
+ pinMode(BTN_LEFT, INPUT_PULLUP);
+ pinMode(BTN_RIGHT, INPUT_PULLUP);
+
+ pinMode(PIN, OUTPUT);
+ strip.begin();
+}
+
+void loop() {
+ if (digitalRead(BTN_LEFT) == LOW)
+ {
+ if (position > 0) position--;
+ }
+ if (digitalRead(BTN_RIGHT) == LOW)
+ {
+ if (position < (NUM_PIXELS - 1)) position++;
+ }
+ delay(50);
+
+ for (int i = 0 ; i < NUM_PIXELS; i++)
+ {
+ if (i == position)
+ {
+ strip.setPixelColor(i, strip.Color(255, 0, 0));
+ }
+ else
+ {
+ strip.setPixelColor(i, strip.Color(0, 0, 255));
+ }
+ }
+ strip.show();
+}
--- /dev/null
+void setup() {
+ // put your setup code here, to run once:
+ Serial.begin(9600);
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+ Serial.print('V');
+ Serial.println('V');
+
+ Serial.write(0x56);
+ while(Serial.available() > 0)
+ {
+ Serial.read();
+ }
+ delay(5000);
+}
-#define BTN_PIN 2
-#define LED_PIN 13
+#define BTN_PIN 2
+#define LED_PIN 13
void button_pressed_ISR(void);
void slow_computation(void);
void setup()
{
- pinMode(BTN_PIN, INPUT_PULLUP);
- pinMode(LED_PIN, OUTPUT);
- attachInterrupt(digitalPinToInterrupt(BTN_PIN), button_pressed_ISR, FALLING);
+ pinMode(BTN_PIN, INPUT_PULLUP);
+ pinMode(LED_PIN, OUTPUT);
+ attachInterrupt(digitalPinToInterrupt(BTN_PIN), button_pressed_ISR, FALLING);
+ //attachInterrupt(digitalPinToInterrupt(BTN_PIN), button_pressed_ISR, RISING);
+ //attachInterrupt(digitalPinToInterrupt(BTN_PIN), button_pressed_ISR, CHANGE);
- Serial.begin(9600);
+ Serial.begin(9600);
}
void loop()
{
- slow_computation();
-
- if (led_state)
- Serial.println("LED in on.");
- else
- Serial.println("LED in off.");
+ slow_computation();
+
+ if (led_state)
+ Serial.println("LED in on.");
+ else
+ Serial.println("LED in off.");
}
void button_pressed_ISR(void)
{
- if (led_state)
- {
- led_state = 0;
- digitalWrite(LED_PIN, LOW);
- }
- else
- {
- led_state = 1;
- digitalWrite(LED_PIN, HIGH);
- }
+ if (led_state)
+ {
+ led_state = 0;
+ digitalWrite(LED_PIN, LOW);
+ }
+ else
+ {
+ led_state = 1;
+ digitalWrite(LED_PIN, HIGH);
+ }
}
void slow_computation(void)
{
- delay(5000);
-}
\ No newline at end of file
+ delay(5000);
+}