+++ /dev/null
-#define LED_ROW1 11 // Active HIGH | Inactive LOW
-#define LED_ROW2 10 // Active HIGH | Inactive LOW
-#define LED_ROW3 9 // Active HIGH | Inactive LOW
-#define LED_COL1 8 // Active LOW | Inactive HIGH
-#define LED_COL2 7 // Active LOW | Inactive HIGH
-#define LED_COL3 6 // Active LOW | Inactive HIGH
-
-#define BTN_ROW1 A3 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
-#define BTN_ROW2 A4 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
-#define BTN_ROW3 A5 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
-#define BTN_COL1 A0 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
-#define BTN_COL2 A1 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
-#define BTN_COL3 A2 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
-
-const uint8_t led_col[3] = {LED_COL1, LED_COL2, LED_COL3};
-const uint8_t led_row[3] = {LED_ROW1, LED_ROW2, LED_ROW3};
-
-const uint8_t btn_col[3] = {BTN_COL1, BTN_COL2, BTN_COL3};
-const uint8_t btn_row[3] = {BTN_ROW1, BTN_ROW2, BTN_ROW3};
-
-uint8_t state_1[3][3] =
-{
- {0, 0, 0},
- {0, 0, 0},
- {0, 0, 0}
-};
-
-void setup()
-{
- int i = 0;
-
- for (i = 0; i < 3; i++)
- {
- pinMode(led_row[i], OUTPUT);
- digitalWrite(led_row[i], LOW);
- pinMode(led_col[i], OUTPUT);
- digitalWrite(led_col[i], HIGH);
-
- pinMode(btn_row[i], INPUT_PULLUP);
- pinMode(btn_col[i], INPUT_PULLUP);
- }
-}
-
-void loop()
-{
- // Button scan
- for (byte col = 0; col < 3; col++)
- {
- pinMode(btn_col[col], OUTPUT);
- digitalWrite(btn_col[col], LOW);
- for (byte row = 0; row < 3; row++)
- {
- state_1[row][col] = !digitalRead(btn_row[row]);
- }
- pinMode(btn_col[col], INPUT_PULLUP);
- }
-
- // Transpose
- for (int i = 0; i < 3; i++)
- {
- for (int j = i + 1; j < 3; j++)
- {
- int temp;
- temp = state_1[i][j];
- state_1[i][j] = state_1[j][i];
- state_1[j][i] = temp;
- }
- }
-
- // LED update
- for (byte col = 0; col < 3; col++)
- {
- for (byte row = 0; row < 3; row++)
- {
- digitalWrite(led_row[row], state_1[row][col]);
- }
- digitalWrite(led_col[col], LOW);
- delay(5);
- digitalWrite(led_col[col], HIGH);
- for (byte row = 0; row < 3; row++)
- {
- digitalWrite(led_row[row], LOW);
- }
- }
-}
+++ /dev/null
-https://www.tinkercad.com/things/bJ9mxNp3wXG
+++ /dev/null
-#include <math.h>
-
-#define A_PIN 12
-#define B_PIN 13
-#define C_PIN 7
-#define D_PIN 8
-#define E_PIN 9
-#define F_PIN 11
-#define G_PIN 10
-#define DP_PIN 6
-#define EN0_PIN 5
-#define EN1_PIN 4
-#define UP_PIN 3
-#define DOWN_PIN 2
-
-#define DIGITS 2
-
-int print_dec(uint16_t value);
-int print_digit(uint8_t position, uint8_t digit);
-void emulate_timer_ISR(void);
-void counter_up(void);
-void counter_down(void);
-
-const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};
-const uint8_t en_pins[DIGITS] = {EN0_PIN, EN1_PIN};
-
-const uint8_t segment_map[16] =
-{
- // A B C D E F G DP
- 0b00000011, // 0
- 0b10011111, // 1
- 0b00100101, // 2
- 0b00001101, // 3
- 0b10011001, // 4
- 0b01001001, // 5
- 0b01000001, // 6
- 0b00011111, // 7
- 0b00000001, // 8
- 0b00001001, // 9
- 0b00010001, // A
- 0b11000001, // b
- 0b01100011, // C
- 0b10000101, // d
- 0b01100001, // E
- 0b01110001 // F
-};
-
-volatile uint8_t display_value[DIGITS] = {0};
-volatile uint8_t current_digit = 0;
-volatile uint8_t counter = 0;
-
-void setup()
-{
- uint8_t i;
- for (i = 0; i < DIGITS; i++)
- {
- pinMode(en_pins[i], OUTPUT);
- digitalWrite(en_pins[i], HIGH);
- }
- for (i = 0; i < 8; i++)
- {
- pinMode(segm_pins[i], OUTPUT);
- digitalWrite(segm_pins[i], HIGH);
- }
- pinMode(UP_PIN, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(UP_PIN), counter_up, FALLING);
- pinMode(DOWN_PIN, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(DOWN_PIN), counter_down, FALLING);
-}
-
-void loop()
-{
- print_dec(counter);
-
- // This is garbage, don't use it!
- for(uint8_t i = 0; i < 10; i++)
- {
- delay(10);
- emulate_timer_ISR();
- }
-}
-
-int print_dec(uint16_t value)
-{
- if (value > (int) pow(10, DIGITS) - 1)
- {
- return -1;
- }
-
- for (uint8_t i = 0; i < DIGITS; i++)
- {
- print_digit(DIGITS - 1 - i, value % 10);
- value /= 10;
- }
-
- return 0;
-}
-
-int print_digit(uint8_t position, uint8_t digit)
-{
- if (position > DIGITS - 1 || digit > 15)
- {
- return -1;
- }
-
- display_value[position] = digit;
-
- return 0;
-}
-
-void emulate_timer_ISR(void)
-{
- digitalWrite(en_pins[current_digit], HIGH);
-
- current_digit++;
- if (current_digit > DIGITS - 1)
- {
- current_digit = 0;
- }
-
- for (uint8_t i = 0; i < 8; i++)
- {
- digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));
- }
-
- digitalWrite(en_pins[current_digit], LOW);
-}
-
-void counter_up(void)
-{
- counter++;
-}
-
-void counter_down(void)
-{
- counter--;
-}
+++ /dev/null
-https://www.tinkercad.com/things/kQ6afgEqekR
+++ /dev/null
-#include <math.h>
-
-#define SW0_PIN A0
-#define SW1_PIN A1
-#define SW2_PIN A2
-#define SW3_PIN A3
-#define SW4_PIN A4
-#define SW5_PIN A5
-#define SW6_PIN 2
-#define SW7_PIN 3
-
-#define A_PIN 12
-#define B_PIN 13
-#define C_PIN 7
-#define D_PIN 8
-#define E_PIN 9
-#define F_PIN 11
-#define G_PIN 10
-#define DP_PIN 6
-#define EN0_PIN 5
-#define EN1_PIN 4
-
-#define DIGITS 2
-
-int print_digit(uint8_t position, uint8_t digit);
-void emulate_timer_ISR(void);
-uint8_t read_sw_slow(void);
-uint8_t read_sw(void);
-
-const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};
-const uint8_t en_pins[DIGITS] = {EN0_PIN, EN1_PIN};
-const uint8_t sw_pins[8] = {SW0_PIN, SW1_PIN, SW2_PIN, SW3_PIN, SW4_PIN, SW5_PIN, SW6_PIN, SW7_PIN};
-
-const uint8_t segment_map[16] =
-{
- // A B C D E F G DP
- 0b00000011, // 0
- 0b10011111, // 1
- 0b00100101, // 2
- 0b00001101, // 3
- 0b10011001, // 4
- 0b01001001, // 5
- 0b01000001, // 6
- 0b00011111, // 7
- 0b00000001, // 8
- 0b00001001, // 9
- 0b00010001, // A
- 0b11000001, // b
- 0b01100011, // C
- 0b10000101, // d
- 0b01100001, // E
- 0b01110001 // F
-};
-
-volatile uint8_t display_value[DIGITS] = {0};
-volatile uint8_t current_digit = 0;
-
-void setup()
-{
- uint8_t i;
- for (i = 0; i < DIGITS; i++)
- {
- pinMode(en_pins[i], OUTPUT);
- digitalWrite(en_pins[i], HIGH);
- }
- for (i = 0; i < 8; i++)
- {
- pinMode(segm_pins[i], OUTPUT);
- digitalWrite(segm_pins[i], HIGH);
- pinMode(sw_pins[i], INPUT_PULLUP);
- }
-}
-
-void loop()
-{
- uint8_t switch_val = read_sw();
- print_digit(0, switch_val >> 4);
- print_digit(1, switch_val & 0x0F);
-
- // This is garbage, don't use it!
- for(uint8_t i = 0; i < 10; i++)
- {
- delay(10);
- emulate_timer_ISR();
- }
-}
-
-int print_digit(uint8_t position, uint8_t digit)
-{
- if (position > DIGITS - 1 || digit > 15)
- {
- return -1;
- }
-
- display_value[position] = digit;
-
- return 0;
-}
-
-void emulate_timer_ISR(void)
-{
- digitalWrite(en_pins[current_digit], HIGH);
-
- current_digit++;
- if (current_digit > DIGITS - 1)
- {
- current_digit = 0;
- }
-
- for (uint8_t i = 0; i < 8; i++)
- {
- digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));
- }
-
- digitalWrite(en_pins[current_digit], LOW);
-}
-
-uint8_t read_sw_slow(void)
-{
- uint8_t switch_value = 0;
-
- for (uint8_t i = 0; i < 8; i++)
- {
- switch_value += !digitalRead(sw_pins[i]) << i;
- }
-
- return switch_value;
-}
-
-uint8_t read_sw(void)
-{
- return (~PINC & 0x3F) | ((~PIND & 0x0C) << 4);
-}
+++ /dev/null
-https://www.tinkercad.com/things/aHW3wNDugHU
+++ /dev/null
-#define DATA1_PIN 2
-#define DATA2_PIN 5
-#define DATA3_PIN 4
-#define DATA4_PIN 3
-#define LATCH1_PIN 9
-#define LATCH2_PIN 8
-#define LATCH3_PIN 7
-#define LATCH4_PIN 6
-#define BLANKING_PIN 10
-
-#define BRIGHTNESS 200 // Maximum 255
-
-int print_digit(uint8_t position, uint8_t digit);
-void pulse_pin(uint8_t pin);
-
-const uint8_t data_pins[4] = {DATA1_PIN, DATA2_PIN, DATA3_PIN, DATA4_PIN};
-const uint8_t latch_pins[4] = {LATCH1_PIN, LATCH2_PIN, LATCH3_PIN, LATCH4_PIN};
-
-void setup()
-{
- for (uint8_t i = 0; i < 4; i++)
- {
- pinMode(data_pins[i], OUTPUT);
- digitalWrite(data_pins[i], LOW);
- pinMode(latch_pins[i], OUTPUT);
- digitalWrite(latch_pins[i], HIGH);
- }
- pinMode(BLANKING_PIN, OUTPUT);
- analogWrite(BLANKING_PIN, BRIGHTNESS);
-}
-
-void loop()
-{
- print_digit(0, 7);
- print_digit(1, 7);
- print_digit(2, 3);
- print_digit(3, 4);
- delay(1000);
-}
-
-int print_digit(uint8_t position, uint8_t digit)
-{
- if (position > 3 || digit > 15)
- {
- return -1;
- }
-
- // Encode the digit on the four data signals to the drivers
- for (uint8_t i = 0; i < 4; i++)
- {
- digitalWrite(data_pins[i], digit & (1 << i));
- }
- // Latch the data
- pulse_pin(latch_pins[position]);
-
- return 0;
-}
-
-void pulse_pin(uint8_t pin)
-{
- // The delay from calling digitalWrite() is enough to satisfy the
- // setup and hold times of CD5411 but we delay some more for good measure.
- delayMicroseconds(5);
- digitalWrite(pin, LOW);
- delayMicroseconds(5);
- digitalWrite(pin, HIGH);
-}
+++ /dev/null
-https://www.tinkercad.com/things/kaVhIKUgeAY
+++ /dev/null
-#include <stdlib.h>
-
-#define DATA1_PIN 12
-#define DATA2_PIN 5
-#define DATA3_PIN 4
-#define DATA4_PIN 13
-#define LATCH0_PIN 11
-#define LATCH1_PIN 9
-#define LATCH2_PIN 8
-#define LATCH3_PIN 7
-#define LATCH4_PIN 6
-#define LATCH5_PIN A5
-#define BLANKING_PIN 10
-
-#define BUTTON_PIN 3
-#define POT_PIN A4
-#define NC_PIN A3
-
-#define DIGITS 6
-#define BRIGHTNESS 200 // Maximum 255
-
-const uint8_t data_pins[4] = {DATA1_PIN, DATA2_PIN, DATA3_PIN, DATA4_PIN};
-const uint8_t latch_pins[DIGITS] = {LATCH0_PIN, LATCH1_PIN, LATCH2_PIN, LATCH3_PIN, LATCH4_PIN, LATCH5_PIN};
-
-volatile uint32_t current_value = 0;
-
-void button_ISR(void);
-void print_7segm(uint32_t val);
-
-void setup()
-{
- Serial.begin(9600);
-
- pinMode(NC_PIN, INPUT);
- srand(analogRead(NC_PIN));
-
- for (uint8_t i = 0; i < 4; i++)
- {
- pinMode(data_pins[i], OUTPUT);
- digitalWrite(data_pins[i], LOW);
- }
- for (uint8_t i = 0; i < DIGITS; i++)
- {
- pinMode(latch_pins[i], OUTPUT);
- digitalWrite(latch_pins[i], HIGH);
- }
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), button_ISR, FALLING);
- pinMode(BLANKING_PIN, OUTPUT);
- digitalWrite(BLANKING_PIN, HIGH);
-}
-
-void loop()
-{
- print_7segm(current_value);
- delay(100);
-}
-
-void button_ISR(void)
-{
- current_value = rand();
- current_value |= ((uint32_t) rand() << 16);
- Serial.print(current_value);
-}
-
-void print_7segm(uint32_t val)
-{
- uint8_t i, j;
- uint8_t digit;
-
- for (i = 0; i < DIGITS; i++)
- {
- digit = val % 10;
- val /= 10;
-
- for (j = 0; j < 4; j++)
- {
- digitalWrite(data_pins[j], digit & (1 << j));
- }
- digitalWrite(latch_pins[DIGITS - i - 1], LOW);
- delay(1);
- digitalWrite(latch_pins[DIGITS - i - 1], HIGH);
- delay(1);
- }
-}
+++ /dev/null
-https://www.tinkercad.com/things/3GNvrtWwhQc
+++ /dev/null
-#define A_PIN 8
-#define B_PIN 9
-#define C_PIN 3
-#define D_PIN 4
-#define E_PIN 5
-#define F_PIN 7
-#define G_PIN 6
-#define DP_PIN 2
-
-int print_digit(uint8_t digit);
-
-const uint8_t pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};
-
-const uint8_t segment_map[16] =
-{
- // A B C D E F G DP
- 0b00000011, // 0
- 0b10011111, // 1
- 0b00100101, // 2
- 0b00001101, // 3
- 0b10011001, // 4
- 0b01001001, // 5
- 0b01000001, // 6
- 0b00011111, // 7
- 0b00000001, // 8
- 0b00001001, // 9
- 0b00010001, // A
- 0b11000001, // b
- 0b01100011, // C
- 0b10000101, // d
- 0b01100001, // E
- 0b01110001 // F
-};
-
-void setup()
-{
- for (uint8_t i = 0; i < 8; i++)
- {
- pinMode(pins[i], OUTPUT);
- digitalWrite(pins[i], HIGH);
- }
-}
-
-void loop()
-{
- for (uint8_t cnt = 0; cnt < 16; cnt++)
- {
- print_digit(cnt);
- delay(1000);
- }
-}
-
-int print_digit(uint8_t digit)
-{
- if (digit > 15)
- {
- return -1;
- }
-
- for (uint8_t i = 0; i < 8; i++)
- {
- digitalWrite(pins[i], segment_map[digit] & (128 >> i));
- }
-
- return 0;
-}
+++ /dev/null
-https://www.tinkercad.com/things/a091SYpyBV8
+++ /dev/null
-#include <math.h>\r
-\r
-#define A_PIN 12\r
-#define B_PIN 13\r
-#define C_PIN 7\r
-#define D_PIN 8\r
-#define E_PIN 9\r
-#define F_PIN 11\r
-#define G_PIN 10\r
-#define DP_PIN 6\r
-#define EN0_PIN 5\r
-#define EN1_PIN 4\r
-#define EN2_PIN 3\r
-#define EN3_PIN 2\r
-\r
-#define DIGITS 4\r
-\r
-int print_dec(uint16_t value);\r
-int print_digit(uint8_t position, uint8_t digit);\r
-void emulate_timer_ISR(void);\r
-\r
-const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};\r
-const uint8_t en_pins[DIGITS] = {EN0_PIN, EN1_PIN, EN2_PIN, EN3_PIN};\r
-\r
-const uint8_t segment_map[16] =\r
-{\r
- // A B C D E F G DP\r
- 0b00000011, // 0\r
- 0b10011111, // 1\r
- 0b00100101, // 2\r
- 0b00001101, // 3\r
- 0b10011001, // 4\r
- 0b01001001, // 5\r
- 0b01000001, // 6\r
- 0b00011111, // 7\r
- 0b00000001, // 8\r
- 0b00001001, // 9\r
- 0b00010001, // A\r
- 0b11000001, // b\r
- 0b01100011, // C\r
- 0b10000101, // d\r
- 0b01100001, // E\r
- 0b01110001 // F\r
-};\r
-\r
-volatile uint8_t display_value[DIGITS] = {0};\r
-volatile uint8_t current_digit = 0;\r
-\r
-void setup()\r
-{\r
- uint8_t i;\r
- for (i = 0; i < DIGITS; i++)\r
- {\r
- pinMode(en_pins[i], OUTPUT);\r
- digitalWrite(en_pins[i], HIGH);\r
- }\r
- for (i = 0; i < 8; i++)\r
- {\r
- pinMode(segm_pins[i], OUTPUT);\r
- digitalWrite(segm_pins[i], HIGH);\r
- }\r
-}\r
-\r
-void loop()\r
-{\r
- for (uint16_t cnt = (int) pow(10, DIGITS) - 1; cnt > 0; cnt--)\r
- {\r
- print_dec(cnt);\r
- \r
- // This is garbage, don't use it!\r
- for(uint8_t i = 0; i < 10; i++)\r
- {\r
- delay(10);\r
- emulate_timer_ISR();\r
- }\r
- }\r
- delay(3000);\r
-}\r
-\r
-int print_dec(uint16_t value)\r
-{\r
- if (value > (int) pow(10, DIGITS) - 1)\r
- {\r
- return -1;\r
- }\r
-\r
- for (uint8_t i = 0; i < DIGITS; i++)\r
- {\r
- print_digit(DIGITS - 1 - i, value % 10);\r
- value /= 10;\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-int print_digit(uint8_t position, uint8_t digit)\r
-{\r
- if (position > DIGITS || digit > 15)\r
- {\r
- return -1;\r
- }\r
-\r
- display_value[position] = digit;\r
-\r
- return 0;\r
-}\r
-\r
-void emulate_timer_ISR(void)\r
-{\r
- digitalWrite(en_pins[current_digit], HIGH);\r
-\r
- current_digit++;\r
- if (current_digit > DIGITS - 1)\r
- {\r
- current_digit = 0;\r
- }\r
-\r
- for (uint8_t i = 0; i < 8; i++)\r
- {\r
- digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));\r
- }\r
-\r
- digitalWrite(en_pins[current_digit], LOW);\r
-}\r
+++ /dev/null
-https://www.tinkercad.com/things/7eGYywVu5PG
+++ /dev/null
-#include <math.h>\r
-\r
-#define A_PIN 12\r
-#define B_PIN 13\r
-#define C_PIN 7\r
-#define D_PIN 8\r
-#define E_PIN 9\r
-#define F_PIN 11\r
-#define G_PIN 10\r
-#define DP_PIN 6\r
-#define EN0_PIN 5\r
-#define EN1_PIN 4\r
-#define EN2_PIN 3\r
-#define EN3_PIN 2\r
-\r
-#define DIGITS 4\r
-\r
-int print_dec(uint16_t value);\r
-int print_digit(uint8_t position, uint8_t digit);\r
-void timer_init(void);\r
-void gpio_init(void);\r
-\r
-const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};\r
-const uint8_t en_pins[DIGITS] = {EN0_PIN, EN1_PIN, EN2_PIN, EN3_PIN};\r
-\r
-const uint8_t segment_map[16] =\r
-{\r
- // A B C D E F G DP\r
- 0b00000011, // 0\r
- 0b10011111, // 1\r
- 0b00100101, // 2\r
- 0b00001101, // 3\r
- 0b10011001, // 4\r
- 0b01001001, // 5\r
- 0b01000001, // 6\r
- 0b00011111, // 7\r
- 0b00000001, // 8\r
- 0b00001001, // 9\r
- 0b00010001, // A\r
- 0b11000001, // b\r
- 0b01100011, // C\r
- 0b10000101, // d\r
- 0b01100001, // E\r
- 0b01110001 // F\r
-};\r
-\r
-volatile uint8_t display_value[DIGITS] = {0};\r
-volatile uint8_t current_digit = 0;\r
-\r
-void setup()\r
-{\r
- gpio_init();\r
- timer_init();\r
-}\r
-\r
-void loop()\r
-{\r
- for (uint16_t cnt = (int) pow(10, DIGITS) - 1; cnt > 0; cnt--)\r
- {\r
- print_dec(cnt);\r
- delay(100);\r
- }\r
- delay(3000);\r
-}\r
-\r
-int print_dec(uint16_t value)\r
-{\r
- if (value > (int) pow(10, DIGITS) - 1)\r
- {\r
- return -1;\r
- }\r
-\r
- for (uint8_t i = 0; i < DIGITS; i++)\r
- {\r
- print_digit(DIGITS - 1 - i, value % 10);\r
- value /= 10;\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-int print_digit(uint8_t position, uint8_t digit)\r
-{\r
- if (position > DIGITS || digit > 15)\r
- {\r
- return -1;\r
- }\r
-\r
- display_value[position] = digit;\r
-\r
- return 0;\r
-}\r
-\r
-ISR(TIMER1_OVF_vect)\r
-{\r
- digitalWrite(en_pins[current_digit], HIGH);\r
-\r
- current_digit++;\r
- if (current_digit > DIGITS - 1)\r
- {\r
- current_digit = 0;\r
- }\r
-\r
- for (uint8_t i = 0; i < 8; i++)\r
- {\r
- digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));\r
- }\r
-\r
- digitalWrite(en_pins[current_digit], LOW);\r
-}\r
-\r
-void gpio_init(void)\r
-{\r
- uint8_t i;\r
- for (i = 0; i < DIGITS; i++)\r
- {\r
- pinMode(en_pins[i], OUTPUT);\r
- digitalWrite(en_pins[i], HIGH);\r
- }\r
- for (i = 0; i < 8; i++)\r
- {\r
- pinMode(segm_pins[i], OUTPUT);\r
- digitalWrite(segm_pins[i], HIGH);\r
- }\r
-}\r
-\r
-void timer_init(void)\r
-{\r
- noInterrupts();\r
- \r
- // After clearing TCCR1B the timer is stopped\r
- TCCR1B = 0;\r
- TCNT1 = 0;\r
- \r
- TCCR1A = (1 << WGM11);\r
- TCCR1B |= (1 << WGM12) | (1 << WGM13);\r
- TIMSK1 = (1 << TOIE1);\r
-\r
- // Set frequency to 1kHz\r
- ICR1 = 1999;\r
- TCCR1B |= (1 << CS11);\r
-\r
- interrupts();\r
-}\r
+++ /dev/null
-:100000000C945C000C9479000C9479000C947900A9
-:100010000C9479000C9479000C9479000C9479007C
-:100020000C9479000C9479000C9479000C9479006C
-:100030000C9479000C9487010C9479000C9479004D
-:100040000C943D010C9479000C9479000C94790087
-:100050000C9479000C9479000C9479000C9479003C
-:100060000C9479000C947900000000080002010053
-:100070000003040700000000000000000000000072
-:10008000250028002B0000000000240027002A0083
-:10009000040404040404040402020202020203032E
-:1000A0000303030301020408102040800102040836
-:1000B000102001020408102011241FBECFEFD8E049
-:1000C000DEBFCDBF11E0A0E0B1E0E8E9F5E002C09D
-:1000D00005900D92AC31B107D9F721E0ACE1B1E068
-:1000E00001C01D92AA32B207E1F70E94F4010C94FC
-:1000F000CA020C94000090E0FC01EC55FF4F2491E3
-:1001000080579F4FFC018491882399F090E0880FDD
-:10011000991FFC01EA57FF4FA591B491FC01E458E7
-:10012000FF4F859194918FB7F894EC91E22BEC936B
-:100130008FBF089590E0FC01E859FF4F2491FC0126
-:10014000EC55FF4F3491FC01E057FF4FE491EE2353
-:10015000C9F0222339F0233001F1A8F4213019F13C
-:10016000223029F1F0E0EE0FFF1FE458FF4FA59178
-:10017000B4918FB7F894EC91611126C030953E236D
-:100180003C938FBF08952730A9F02830C9F0243060
-:1001900049F7809180008F7D03C0809180008F7728
-:1001A00080938000DFCF84B58F7784BDDBCF84B5AB
-:1001B0008F7DFBCF8091B0008F778093B000D2CF3E
-:1001C0008091B0008F7DF9CF3E2BDACF3FB7F89406
-:1001D0008091220190912301A0912401B0912501E9
-:1001E00026B5A89B05C02F3F19F00196A11DB11D92
-:1001F0003FBFBA2FA92F982F8827BC01CD01620FCE
-:10020000711D811D911D42E0660F771F881F991F88
-:100210004A95D1F708958F929F92AF92BF92CF9255
-:10022000DF92EF92FF924B015C010E94E6006B01AE
-:100230007C010E94E6006C197D098E099F09683EC9
-:10024000734081059105A8F321E0821A9108A10865
-:10025000B10888EEC80E83E0D81EE11CF11C8114A1
-:100260009104A104B10429F7FF90EF90DF90CF90A3
-:10027000BF90AF909F908F9008951F920F920FB6EE
-:100280000F9211242F933F938F939F93AF93BF931C
-:1002900080911E0190911F01A0912001B091210138
-:1002A00030911D0123E0230F2D3758F50196A11D34
-:1002B000B11D20931D0180931E0190931F01A093F7
-:1002C0002001B09321018091220190912301A091FE
-:1002D0002401B09125010196A11DB11D8093220139
-:1002E00090932301A0932401B0932501BF91AF9176
-:1002F0009F918F913F912F910F900FBE0F901F9064
-:10030000189526E8230F0296A11DB11DD2CF1F928A
-:100310000F920FB60F921124EF92FF920F931F933B
-:100320002F933F934F935F936F937F938F939F93FD
-:10033000AF93BF93CF93DF93EF93FF93E0911C01B3
-:10034000F0E0E85EFE4F61E080810E949A008091BB
-:100350001C018F5F80931C0180911C01843010F080
-:1003600010921C0100E111E0D0E0C0E080E8E82E2E
-:10037000F12CE0911C01F0E0EA5DFE4FE081F0E03D
-:10038000E050FF4FC7010C2E02C0959587950A9447
-:10039000E2F760816823F80181918F010E949A0041
-:1003A0002196C830D10529F7E0911C01F0E0E85E04
-:1003B000FE4F60E080810E949A00FF91EF91DF91F3
-:1003C000CF91BF91AF919F918F917F916F915F91ED
-:1003D0004F913F912F911F910F91FF90EF900F90B0
-:1003E0000FBE0F901F901895789484B5826084BDDD
-:1003F00084B5816084BD85B5826085BD85B5816029
-:1004000085BD80916E00816080936E0010928100A6
-:100410008091810082608093810080918100816061
-:100420008093810080918000816080938000809122
-:10043000B10084608093B1008091B00081608093AE
-:10044000B00080917A00846080937A0080917A0075
-:10045000826080937A0080917A00816080937A0034
-:1004600080917A00806880937A001092C100C8E180
-:10047000D1E04CE1E42E41E0F42E1991812F0E944D
-:100480007B0061E0812F0E949A00EC16FD06A9F71F
-:10049000C0E1D1E038E1E32E31E0F32E1991812F54
-:1004A0000E947B0061E0812F0E949A00EC16FD06FD
-:1004B000A9F7F894109281001092850010928400A0
-:1004C00082E0809380008091810088618093810028
-:1004D00081E080936F008FEC97E09093870080938A
-:1004E00086008091810082608093810078940AE088
-:1004F00010E084E6E82EF12C98EEC92E93E0D92E78
-:1005000020E0A22E20E0B22ECFE0D7E2CE01B8014B
-:100510000E94B60280932901CB01B8010E94B60265
-:1005200080932801CE01B7010E94B602CB01B80129
-:100530000E94B60280932701CE01B6010E94B60246
-:100540006093260164E670E080E090E00E940B0179
-:100550002197E1F668EB7BE080E090E00E940B01E0
-:10056000A114B10489F20E940000CECFAA1BBB1BCC
-:1005700051E107C0AA1FBB1FA617B70710F0A61BA3
-:10058000B70B881F991F5A95A9F780959095BC01C4
-:08059000CD010895F894FFCF9E
-:10059800039F250D9949411F010911C163856171A7
-:0C05A8000C0D0708090B0A0605040302ED
-:00000001FF
+++ /dev/null
-:020000040000FA
-:100000000C945C000C9479000C9479000C947900A9
-:100010000C9479000C9479000C9479000C9479007C
-:100020000C9479000C9479000C9479000C9479006C
-:100030000C9479000C9487010C9479000C9479004D
-:100040000C943D010C9479000C9479000C94790087
-:100050000C9479000C9479000C9479000C9479003C
-:100060000C9479000C947900000000080002010053
-:100070000003040700000000000000000000000072
-:10008000250028002B0000000000240027002A0083
-:10009000040404040404040402020202020203032E
-:1000A0000303030301020408102040800102040836
-:1000B000102001020408102011241FBECFEFD8E049
-:1000C000DEBFCDBF11E0A0E0B1E0E8E9F5E002C09D
-:1000D00005900D92AC31B107D9F721E0ACE1B1E068
-:1000E00001C01D92AA32B207E1F70E94F4010C94FC
-:1000F000CA020C94000090E0FC01EC55FF4F2491E3
-:1001000080579F4FFC018491882399F090E0880FDD
-:10011000991FFC01EA57FF4FA591B491FC01E458E7
-:10012000FF4F859194918FB7F894EC91E22BEC936B
-:100130008FBF089590E0FC01E859FF4F2491FC0126
-:10014000EC55FF4F3491FC01E057FF4FE491EE2353
-:10015000C9F0222339F0233001F1A8F4213019F13C
-:10016000223029F1F0E0EE0FFF1FE458FF4FA59178
-:10017000B4918FB7F894EC91611126C030953E236D
-:100180003C938FBF08952730A9F02830C9F0243060
-:1001900049F7809180008F7D03C0809180008F7728
-:1001A00080938000DFCF84B58F7784BDDBCF84B5AB
-:1001B0008F7DFBCF8091B0008F778093B000D2CF3E
-:1001C0008091B0008F7DF9CF3E2BDACF3FB7F89406
-:1001D0008091220190912301A0912401B0912501E9
-:1001E00026B5A89B05C02F3F19F00196A11DB11D92
-:1001F0003FBFBA2FA92F982F8827BC01CD01620FCE
-:10020000711D811D911D42E0660F771F881F991F88
-:100210004A95D1F708958F929F92AF92BF92CF9255
-:10022000DF92EF92FF924B015C010E94E6006B01AE
-:100230007C010E94E6006C197D098E099F09683EC9
-:10024000734081059105A8F321E0821A9108A10865
-:10025000B10888EEC80E83E0D81EE11CF11C8114A1
-:100260009104A104B10429F7FF90EF90DF90CF90A3
-:10027000BF90AF909F908F9008951F920F920FB6EE
-:100280000F9211242F933F938F939F93AF93BF931C
-:1002900080911E0190911F01A0912001B091210138
-:1002A00030911D0123E0230F2D3758F50196A11D34
-:1002B000B11D20931D0180931E0190931F01A093F7
-:1002C0002001B09321018091220190912301A091FE
-:1002D0002401B09125010196A11DB11D8093220139
-:1002E00090932301A0932401B0932501BF91AF9176
-:1002F0009F918F913F912F910F900FBE0F901F9064
-:10030000189526E8230F0296A11DB11DD2CF1F928A
-:100310000F920FB60F921124EF92FF920F931F933B
-:100320002F933F934F935F936F937F938F939F93FD
-:10033000AF93BF93CF93DF93EF93FF93E0911C01B3
-:10034000F0E0E85EFE4F61E080810E949A008091BB
-:100350001C018F5F80931C0180911C01843010F080
-:1003600010921C0100E111E0D0E0C0E080E8E82E2E
-:10037000F12CE0911C01F0E0EA5DFE4FE081F0E03D
-:10038000E050FF4FC7010C2E02C0959587950A9447
-:10039000E2F760816823F80181918F010E949A0041
-:1003A0002196C830D10529F7E0911C01F0E0E85E04
-:1003B000FE4F60E080810E949A00FF91EF91DF91F3
-:1003C000CF91BF91AF919F918F917F916F915F91ED
-:1003D0004F913F912F911F910F91FF90EF900F90B0
-:1003E0000FBE0F901F901895789484B5826084BDDD
-:1003F00084B5816084BD85B5826085BD85B5816029
-:1004000085BD80916E00816080936E0010928100A6
-:100410008091810082608093810080918100816061
-:100420008093810080918000816080938000809122
-:10043000B10084608093B1008091B00081608093AE
-:10044000B00080917A00846080937A0080917A0075
-:10045000826080937A0080917A00816080937A0034
-:1004600080917A00806880937A001092C100C8E180
-:10047000D1E04CE1E42E41E0F42E1991812F0E944D
-:100480007B0061E0812F0E949A00EC16FD06A9F71F
-:10049000C0E1D1E038E1E32E31E0F32E1991812F54
-:1004A0000E947B0061E0812F0E949A00EC16FD06FD
-:1004B000A9F7F894109281001092850010928400A0
-:1004C00082E0809380008091810088618093810028
-:1004D00081E080936F008FEC97E09093870080938A
-:1004E00086008091810082608093810078940AE088
-:1004F00010E084E6E82EF12C98EEC92E93E0D92E78
-:1005000020E0A22E20E0B22ECFE0D7E2CE01B8014B
-:100510000E94B60280932901CB01B8010E94B60265
-:1005200080932801CE01B7010E94B602CB01B80129
-:100530000E94B60280932701CE01B6010E94B60246
-:100540006093260164E670E080E090E00E940B0179
-:100550002197E1F668EB7BE080E090E00E940B01E0
-:10056000A114B10489F20E940000CECFAA1BBB1BCC
-:1005700051E107C0AA1FBB1FA617B70710F0A61BA3
-:10058000B70B881F991F5A95A9F780959095BC01C4
-:10059000CD010895F894FFCF039F250D9949411F80
-:1005A000010911C1638561710C0D0708090B0A0669
-:0405B0000504030239
-:107E0000112484B714BE81FFF0D085E080938100F7
-:107E100082E08093C00088E18093C10086E0809377
-:107E2000C20080E18093C4008EE0C9D0259A86E02C
-:107E300020E33CEF91E0309385002093840096BBD3
-:107E4000B09BFECF1D9AA8958150A9F7CC24DD24C4
-:107E500088248394B5E0AB2EA1E19A2EF3E0BF2EE7
-:107E6000A2D0813461F49FD0082FAFD0023811F036
-:107E7000013811F484E001C083E08DD089C08234E0
-:107E800011F484E103C0853419F485E0A6D080C0E4
-:107E9000853579F488D0E82EFF2485D0082F10E0AE
-:107EA000102F00270E291F29000F111F8ED06801E7
-:107EB0006FC0863521F484E090D080E0DECF843638
-:107EC00009F040C070D06FD0082F6DD080E0C81688
-:107ED00080E7D80618F4F601B7BEE895C0E0D1E017
-:107EE00062D089930C17E1F7F0E0CF16F0E7DF06D8
-:107EF00018F0F601B7BEE89568D007B600FCFDCFD4
-:107F0000A601A0E0B1E02C9130E011968C91119780
-:107F100090E0982F8827822B932B1296FA010C0160
-:107F200087BEE89511244E5F5F4FF1E0A038BF0790
-:107F300051F7F601A7BEE89507B600FCFDCF97BE46
-:107F4000E89526C08437B1F42ED02DD0F82E2BD052
-:107F50003CD0F601EF2C8F010F5F1F4F84911BD097
-:107F6000EA94F801C1F70894C11CD11CFA94CF0C13
-:107F7000D11C0EC0853739F428D08EE10CD085E9AC
-:107F80000AD08FE07ACF813511F488E018D01DD067
-:107F900080E101D065CF982F8091C00085FFFCCF94
-:107FA0009093C60008958091C00087FFFCCF809118
-:107FB000C00084FD01C0A8958091C6000895E0E648
-:107FC000F0E098E1908380830895EDDF803219F02E
-:107FD00088E0F5DFFFCF84E1DECF1F93182FE3DFCA
-:107FE0001150E9F7F2DF1F91089580E0E8DFEE27F6
-:047FF000FF270994CA
-:027FFE00040479
-:00000001FF
+++ /dev/null
-<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\r
-<WORKSPACE>\r
- <FRAME activewindow="0">\r
- <PLACEMENT>2c0000000200000003000000ffffffffffffffffffffffffffffffffab0000000d000000d606000004040000</PLACEMENT>\r
- <WINDOW type="default" module="ISIS"/>\r
- <WINDOW type="device" module="LIBMAN"/>\r
- </FRAME>\r
- <MODULE name="VSMDEBUG">\r
- <PWI>\r
- <POPUP w="800" x="38" flags="00000002" y="129" h="200" pid="0" iid="-1">\r
- <PROPERTIES>\r
- <ITEM name="Message Column Width">542</ITEM>\r
- <ITEM name="ShowGrid">No</ITEM>\r
- <ITEM name="Source Column Width">100</ITEM>\r
- <ITEM name="Time Column Width">120</ITEM>\r
- <ITEM name="Version">100</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="350" x="58" flags="00000032" y="149" h="200" pid="1" iid="-1">\r
- <PROPERTIES>\r
- <ITEM name="Address Column Width">83</ITEM>\r
- <ITEM name="AutoResize">No</ITEM>\r
- <ITEM name="Gridlines">Yes</ITEM>\r
- <ITEM name="Name Column Width">83</ITEM>\r
- <ITEM name="ShowAddresses">Yes</ITEM>\r
- <ITEM name="ShowPreviousValues">No</ITEM>\r
- <ITEM name="ShowTypes">No</ITEM>\r
- <ITEM name="ShowWatchPoint">Yes</ITEM>\r
- <ITEM name="TriggerMode">0</ITEM>\r
- <ITEM name="Value Column Width">83</ITEM>\r
- <ITEM name="Version">100</ITEM>\r
- <ITEM name="Watch Expression Column Width">83</ITEM>\r
- <ITEM name="nItems">0</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="226" x="78" flags="00000008" y="169" h="215" pid="3" iid="1">\r
- <PROPERTIES/>\r
- </POPUP>\r
- <POPUP w="8" x="98" flags="0000000a" y="189" h="1" pid="10" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000000</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="8" x="118" flags="0000000a" y="209" h="32" pid="6" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000000</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="16" x="138" flags="0000000a" y="229" h="32" pid="7" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000000</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="16" x="158" flags="80000000" y="249" h="32" pid="14" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000000</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="16" x="178" flags="0000000a" y="269" h="32" pid="4" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000100</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="16" x="198" flags="0000000a" y="289" h="8" pid="13" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000020</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- </PWI>\r
- </MODULE>\r
-</WORKSPACE>\r
+++ /dev/null
-<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
-<WORKSPACE>
- <FRAME activewindow="0">
- <PLACEMENT>2c00000002000000030000000083ffff0083ffffffffffffffffffffb20000000c000000ce060000fa030000</PLACEMENT>
- <WINDOW type="default" module="ISIS"/>
- </FRAME>
- <MODULE name="VSMDEBUG">
- <PWI>
- <POPUP w="400" x="5" flags="00000002" y="87" h="100" pid="0" iid="-1">
- <PROPERTIES>
- <ITEM name="Message Column Width">142</ITEM>
- <ITEM name="ShowGrid">No</ITEM>
- <ITEM name="Source Column Width">100</ITEM>
- <ITEM name="Time Column Width">120</ITEM>
- <ITEM name="Version">100</ITEM>
- </PROPERTIES>
- </POPUP>
- <POPUP w="350" x="5" flags="00000032" y="87" h="100" pid="1" iid="-1">
- <PROPERTIES>
- <ITEM name="Address Column Width">83</ITEM>
- <ITEM name="AutoResize">No</ITEM>
- <ITEM name="Gridlines">Yes</ITEM>
- <ITEM name="Name Column Width">83</ITEM>
- <ITEM name="ShowAddresses">Yes</ITEM>
- <ITEM name="ShowPreviousValues">No</ITEM>
- <ITEM name="ShowTypes">No</ITEM>
- <ITEM name="ShowWatchPoint">Yes</ITEM>
- <ITEM name="TriggerMode">0</ITEM>
- <ITEM name="Value Column Width">83</ITEM>
- <ITEM name="Version">100</ITEM>
- <ITEM name="Watch Expression Column Width">83</ITEM>
- <ITEM name="nItems">0</ITEM>
- </PROPERTIES>
- </POPUP>
- <POPUP w="30" x="5" flags="00000008" y="87" h="16" pid="3" iid="1">
- <PROPERTIES/>
- </POPUP>
- <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="10" iid="1">
- <PROPERTIES>
- <ITEM name="DataType">2</ITEM>
- <ITEM name="DispChars">Yes</ITEM>
- <ITEM name="DispFormat">2</ITEM>
- <ITEM name="ShowChanges">Yes</ITEM>
- <ITEM name="ShowToolTips">Yes</ITEM>
- <ITEM name="TopLineAddress">00000000</ITEM>
- </PROPERTIES>
- </POPUP>
- <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="6" iid="1">
- <PROPERTIES>
- <ITEM name="DataType">2</ITEM>
- <ITEM name="DispChars">Yes</ITEM>
- <ITEM name="DispFormat">2</ITEM>
- <ITEM name="ShowChanges">Yes</ITEM>
- <ITEM name="ShowToolTips">Yes</ITEM>
- <ITEM name="TopLineAddress">00000000</ITEM>
- </PROPERTIES>
- </POPUP>
- <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="7" iid="1">
- <PROPERTIES>
- <ITEM name="DataType">2</ITEM>
- <ITEM name="DispChars">Yes</ITEM>
- <ITEM name="DispFormat">2</ITEM>
- <ITEM name="ShowChanges">Yes</ITEM>
- <ITEM name="ShowToolTips">Yes</ITEM>
- <ITEM name="TopLineAddress">00000000</ITEM>
- </PROPERTIES>
- </POPUP>
- <POPUP w="16" x="188" flags="00000000" y="256" h="32" pid="14" iid="1">
- <PROPERTIES>
- <ITEM name="DataType">2</ITEM>
- <ITEM name="DispChars">Yes</ITEM>
- <ITEM name="DispFormat">2</ITEM>
- <ITEM name="ShowChanges">Yes</ITEM>
- <ITEM name="ShowToolTips">Yes</ITEM>
- <ITEM name="TopLineAddress">00000000</ITEM>
- </PROPERTIES>
- </POPUP>
- <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="4" iid="1">
- <PROPERTIES>
- <ITEM name="DataType">2</ITEM>
- <ITEM name="DispChars">Yes</ITEM>
- <ITEM name="DispFormat">2</ITEM>
- <ITEM name="ShowChanges">Yes</ITEM>
- <ITEM name="ShowToolTips">Yes</ITEM>
- <ITEM name="TopLineAddress">00000100</ITEM>
- </PROPERTIES>
- </POPUP>
- <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="13" iid="1">
- <PROPERTIES>
- <ITEM name="DataType">2</ITEM>
- <ITEM name="DispChars">Yes</ITEM>
- <ITEM name="DispFormat">2</ITEM>
- <ITEM name="ShowChanges">Yes</ITEM>
- <ITEM name="ShowToolTips">Yes</ITEM>
- <ITEM name="TopLineAddress">00000020</ITEM>
- </PROPERTIES>
- </POPUP>
- </PWI>
- </MODULE>
-</WORKSPACE>
+++ /dev/null
-#define LATCH_PIN 4
-#define CLK_PIN 7
-#define SDI_PIN 8
-
-int print_digit(uint8_t segment, uint8_t value);
-
-// Segment map to select number 0 to F
-const uint8_t SEGMENT_MAP[16] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E};
-// Byte map to select digit 0 to 3
-const uint8_t SEGMENT_SELECT[4] = {0xF1, 0xF2, 0xF4, 0xF8};
-
-void setup()
-{
- pinMode(LATCH_PIN, OUTPUT);
- pinMode(CLK_PIN, OUTPUT);
- pinMode(SDI_PIN, OUTPUT);
- digitalWrite(LATCH_PIN, LOW);
- digitalWrite(CLK_PIN, LOW);
- digitalWrite(SDI_PIN, LOW);
-}
-
-void loop()
-{
- print_digit(0, 5);
- print_digit(1, 6);
- print_digit(2, 7);
- print_digit(3, 9);
-}
-
-// Write a decimal number between 0 and 9 to one of the 4 digits of the display
-int print_digit(uint8_t segment, uint8_t value)
-{
- if (value > 15 || segment > 3)
- {
- return -1;
- }
-
- shiftOut(SDI_PIN, CLK_PIN, MSBFIRST, SEGMENT_MAP[value]);
- shiftOut(SDI_PIN, CLK_PIN, MSBFIRST, SEGMENT_SELECT[segment] );
- digitalWrite(LATCH_PIN, HIGH);
- digitalWrite(LATCH_PIN, LOW);
-
- return 0;
-}
--- /dev/null
+#include <math.h>
+
+#define A_PIN 12
+#define B_PIN 13
+#define C_PIN 7
+#define D_PIN 8
+#define E_PIN 9
+#define F_PIN 11
+#define G_PIN 10
+#define DP_PIN 6
+#define EN0_PIN 5
+#define EN1_PIN 4
+#define UP_PIN 3
+#define DOWN_PIN 2
+
+#define DIGITS 2
+
+int print_dec(uint16_t value);
+int print_digit(uint8_t position, uint8_t digit);
+void emulate_timer_ISR(void);
+void counter_up(void);
+void counter_down(void);
+
+const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};
+const uint8_t en_pins[DIGITS] = {EN0_PIN, EN1_PIN};
+
+const uint8_t segment_map[16] =
+{
+ // A B C D E F G DP
+ 0b00000011, // 0
+ 0b10011111, // 1
+ 0b00100101, // 2
+ 0b00001101, // 3
+ 0b10011001, // 4
+ 0b01001001, // 5
+ 0b01000001, // 6
+ 0b00011111, // 7
+ 0b00000001, // 8
+ 0b00001001, // 9
+ 0b00010001, // A
+ 0b11000001, // b
+ 0b01100011, // C
+ 0b10000101, // d
+ 0b01100001, // E
+ 0b01110001 // F
+};
+
+volatile uint8_t display_value[DIGITS] = {0};
+volatile uint8_t current_digit = 0;
+volatile uint8_t counter = 0;
+
+void setup()
+{
+ uint8_t i;
+ for (i = 0; i < DIGITS; i++)
+ {
+ pinMode(en_pins[i], OUTPUT);
+ digitalWrite(en_pins[i], HIGH);
+ }
+ for (i = 0; i < 8; i++)
+ {
+ pinMode(segm_pins[i], OUTPUT);
+ digitalWrite(segm_pins[i], HIGH);
+ }
+ pinMode(UP_PIN, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(UP_PIN), counter_up, FALLING);
+ pinMode(DOWN_PIN, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(DOWN_PIN), counter_down, FALLING);
+}
+
+void loop()
+{
+ print_dec(counter);
+
+ // This is garbage, don't use it!
+ for(uint8_t i = 0; i < 10; i++)
+ {
+ delay(10);
+ emulate_timer_ISR();
+ }
+}
+
+int print_dec(uint16_t value)
+{
+ if (value > (int) pow(10, DIGITS) - 1)
+ {
+ return -1;
+ }
+
+ for (uint8_t i = 0; i < DIGITS; i++)
+ {
+ print_digit(DIGITS - 1 - i, value % 10);
+ value /= 10;
+ }
+
+ return 0;
+}
+
+int print_digit(uint8_t position, uint8_t digit)
+{
+ if (position > DIGITS - 1 || digit > 15)
+ {
+ return -1;
+ }
+
+ display_value[position] = digit;
+
+ return 0;
+}
+
+void emulate_timer_ISR(void)
+{
+ digitalWrite(en_pins[current_digit], HIGH);
+
+ current_digit++;
+ if (current_digit > DIGITS - 1)
+ {
+ current_digit = 0;
+ }
+
+ for (uint8_t i = 0; i < 8; i++)
+ {
+ digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));
+ }
+
+ digitalWrite(en_pins[current_digit], LOW);
+}
+
+void counter_up(void)
+{
+ counter++;
+}
+
+void counter_down(void)
+{
+ counter--;
+}
--- /dev/null
+https://www.tinkercad.com/things/kQ6afgEqekR
--- /dev/null
+#include <math.h>
+
+#define SW0_PIN A0
+#define SW1_PIN A1
+#define SW2_PIN A2
+#define SW3_PIN A3
+#define SW4_PIN A4
+#define SW5_PIN A5
+#define SW6_PIN 2
+#define SW7_PIN 3
+
+#define A_PIN 12
+#define B_PIN 13
+#define C_PIN 7
+#define D_PIN 8
+#define E_PIN 9
+#define F_PIN 11
+#define G_PIN 10
+#define DP_PIN 6
+#define EN0_PIN 5
+#define EN1_PIN 4
+
+#define DIGITS 2
+
+int print_digit(uint8_t position, uint8_t digit);
+void emulate_timer_ISR(void);
+uint8_t read_sw_slow(void);
+uint8_t read_sw(void);
+
+const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};
+const uint8_t en_pins[DIGITS] = {EN0_PIN, EN1_PIN};
+const uint8_t sw_pins[8] = {SW0_PIN, SW1_PIN, SW2_PIN, SW3_PIN, SW4_PIN, SW5_PIN, SW6_PIN, SW7_PIN};
+
+const uint8_t segment_map[16] =
+{
+ // A B C D E F G DP
+ 0b00000011, // 0
+ 0b10011111, // 1
+ 0b00100101, // 2
+ 0b00001101, // 3
+ 0b10011001, // 4
+ 0b01001001, // 5
+ 0b01000001, // 6
+ 0b00011111, // 7
+ 0b00000001, // 8
+ 0b00001001, // 9
+ 0b00010001, // A
+ 0b11000001, // b
+ 0b01100011, // C
+ 0b10000101, // d
+ 0b01100001, // E
+ 0b01110001 // F
+};
+
+volatile uint8_t display_value[DIGITS] = {0};
+volatile uint8_t current_digit = 0;
+
+void setup()
+{
+ uint8_t i;
+ for (i = 0; i < DIGITS; i++)
+ {
+ pinMode(en_pins[i], OUTPUT);
+ digitalWrite(en_pins[i], HIGH);
+ }
+ for (i = 0; i < 8; i++)
+ {
+ pinMode(segm_pins[i], OUTPUT);
+ digitalWrite(segm_pins[i], HIGH);
+ pinMode(sw_pins[i], INPUT_PULLUP);
+ }
+}
+
+void loop()
+{
+ uint8_t switch_val = read_sw();
+ print_digit(0, switch_val >> 4);
+ print_digit(1, switch_val & 0x0F);
+
+ // This is garbage, don't use it!
+ for(uint8_t i = 0; i < 10; i++)
+ {
+ delay(10);
+ emulate_timer_ISR();
+ }
+}
+
+int print_digit(uint8_t position, uint8_t digit)
+{
+ if (position > DIGITS - 1 || digit > 15)
+ {
+ return -1;
+ }
+
+ display_value[position] = digit;
+
+ return 0;
+}
+
+void emulate_timer_ISR(void)
+{
+ digitalWrite(en_pins[current_digit], HIGH);
+
+ current_digit++;
+ if (current_digit > DIGITS - 1)
+ {
+ current_digit = 0;
+ }
+
+ for (uint8_t i = 0; i < 8; i++)
+ {
+ digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));
+ }
+
+ digitalWrite(en_pins[current_digit], LOW);
+}
+
+uint8_t read_sw_slow(void)
+{
+ uint8_t switch_value = 0;
+
+ for (uint8_t i = 0; i < 8; i++)
+ {
+ switch_value += !digitalRead(sw_pins[i]) << i;
+ }
+
+ return switch_value;
+}
+
+uint8_t read_sw(void)
+{
+ return (~PINC & 0x3F) | ((~PIND & 0x0C) << 4);
+}
--- /dev/null
+https://www.tinkercad.com/things/aHW3wNDugHU
--- /dev/null
+#define DATA1_PIN 2
+#define DATA2_PIN 5
+#define DATA3_PIN 4
+#define DATA4_PIN 3
+#define LATCH1_PIN 9
+#define LATCH2_PIN 8
+#define LATCH3_PIN 7
+#define LATCH4_PIN 6
+#define BLANKING_PIN 10
+
+#define BRIGHTNESS 200 // Maximum 255
+
+int print_digit(uint8_t position, uint8_t digit);
+void pulse_pin(uint8_t pin);
+
+const uint8_t data_pins[4] = {DATA1_PIN, DATA2_PIN, DATA3_PIN, DATA4_PIN};
+const uint8_t latch_pins[4] = {LATCH1_PIN, LATCH2_PIN, LATCH3_PIN, LATCH4_PIN};
+
+void setup()
+{
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ pinMode(data_pins[i], OUTPUT);
+ digitalWrite(data_pins[i], LOW);
+ pinMode(latch_pins[i], OUTPUT);
+ digitalWrite(latch_pins[i], HIGH);
+ }
+ pinMode(BLANKING_PIN, OUTPUT);
+ analogWrite(BLANKING_PIN, BRIGHTNESS);
+}
+
+void loop()
+{
+ print_digit(0, 7);
+ print_digit(1, 7);
+ print_digit(2, 3);
+ print_digit(3, 4);
+ delay(1000);
+}
+
+int print_digit(uint8_t position, uint8_t digit)
+{
+ if (position > 3 || digit > 15)
+ {
+ return -1;
+ }
+
+ // Encode the digit on the four data signals to the drivers
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ digitalWrite(data_pins[i], digit & (1 << i));
+ }
+ // Latch the data
+ pulse_pin(latch_pins[position]);
+
+ return 0;
+}
+
+void pulse_pin(uint8_t pin)
+{
+ // The delay from calling digitalWrite() is enough to satisfy the
+ // setup and hold times of CD5411 but we delay some more for good measure.
+ delayMicroseconds(5);
+ digitalWrite(pin, LOW);
+ delayMicroseconds(5);
+ digitalWrite(pin, HIGH);
+}
--- /dev/null
+https://www.tinkercad.com/things/kaVhIKUgeAY
--- /dev/null
+#include <stdlib.h>
+
+#define DATA1_PIN 12
+#define DATA2_PIN 5
+#define DATA3_PIN 4
+#define DATA4_PIN 13
+#define LATCH0_PIN 11
+#define LATCH1_PIN 9
+#define LATCH2_PIN 8
+#define LATCH3_PIN 7
+#define LATCH4_PIN 6
+#define LATCH5_PIN A5
+#define BLANKING_PIN 10
+
+#define BUTTON_PIN 3
+#define POT_PIN A4
+#define NC_PIN A3
+
+#define DIGITS 6
+#define BRIGHTNESS 200 // Maximum 255
+
+const uint8_t data_pins[4] = {DATA1_PIN, DATA2_PIN, DATA3_PIN, DATA4_PIN};
+const uint8_t latch_pins[DIGITS] = {LATCH0_PIN, LATCH1_PIN, LATCH2_PIN, LATCH3_PIN, LATCH4_PIN, LATCH5_PIN};
+
+volatile uint32_t current_value = 0;
+
+void button_ISR(void);
+void print_7segm(uint32_t val);
+
+void setup()
+{
+ Serial.begin(9600);
+
+ pinMode(NC_PIN, INPUT);
+ srand(analogRead(NC_PIN));
+
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ pinMode(data_pins[i], OUTPUT);
+ digitalWrite(data_pins[i], LOW);
+ }
+ for (uint8_t i = 0; i < DIGITS; i++)
+ {
+ pinMode(latch_pins[i], OUTPUT);
+ digitalWrite(latch_pins[i], HIGH);
+ }
+ pinMode(BUTTON_PIN, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), button_ISR, FALLING);
+ pinMode(BLANKING_PIN, OUTPUT);
+ digitalWrite(BLANKING_PIN, HIGH);
+}
+
+void loop()
+{
+ print_7segm(current_value);
+ delay(100);
+}
+
+void button_ISR(void)
+{
+ current_value = rand();
+ current_value |= ((uint32_t) rand() << 16);
+ Serial.print(current_value);
+}
+
+void print_7segm(uint32_t val)
+{
+ uint8_t i, j;
+ uint8_t digit;
+
+ for (i = 0; i < DIGITS; i++)
+ {
+ digit = val % 10;
+ val /= 10;
+
+ for (j = 0; j < 4; j++)
+ {
+ digitalWrite(data_pins[j], digit & (1 << j));
+ }
+ digitalWrite(latch_pins[DIGITS - i - 1], LOW);
+ delay(1);
+ digitalWrite(latch_pins[DIGITS - i - 1], HIGH);
+ delay(1);
+ }
+}
--- /dev/null
+https://www.tinkercad.com/things/3GNvrtWwhQc
--- /dev/null
+#define A_PIN 8
+#define B_PIN 9
+#define C_PIN 3
+#define D_PIN 4
+#define E_PIN 5
+#define F_PIN 7
+#define G_PIN 6
+#define DP_PIN 2
+
+int print_digit(uint8_t digit);
+
+const uint8_t pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};
+
+const uint8_t segment_map[16] =
+{
+ // A B C D E F G DP
+ 0b00000011, // 0
+ 0b10011111, // 1
+ 0b00100101, // 2
+ 0b00001101, // 3
+ 0b10011001, // 4
+ 0b01001001, // 5
+ 0b01000001, // 6
+ 0b00011111, // 7
+ 0b00000001, // 8
+ 0b00001001, // 9
+ 0b00010001, // A
+ 0b11000001, // b
+ 0b01100011, // C
+ 0b10000101, // d
+ 0b01100001, // E
+ 0b01110001 // F
+};
+
+void setup()
+{
+ for (uint8_t i = 0; i < 8; i++)
+ {
+ pinMode(pins[i], OUTPUT);
+ digitalWrite(pins[i], HIGH);
+ }
+}
+
+void loop()
+{
+ for (uint8_t cnt = 0; cnt < 16; cnt++)
+ {
+ print_digit(cnt);
+ delay(1000);
+ }
+}
+
+int print_digit(uint8_t digit)
+{
+ if (digit > 15)
+ {
+ return -1;
+ }
+
+ for (uint8_t i = 0; i < 8; i++)
+ {
+ digitalWrite(pins[i], segment_map[digit] & (128 >> i));
+ }
+
+ return 0;
+}
--- /dev/null
+https://www.tinkercad.com/things/a091SYpyBV8
--- /dev/null
+#include <math.h>\r
+\r
+#define A_PIN 12\r
+#define B_PIN 13\r
+#define C_PIN 7\r
+#define D_PIN 8\r
+#define E_PIN 9\r
+#define F_PIN 11\r
+#define G_PIN 10\r
+#define DP_PIN 6\r
+#define EN0_PIN 5\r
+#define EN1_PIN 4\r
+#define EN2_PIN 3\r
+#define EN3_PIN 2\r
+\r
+#define DIGITS 4\r
+\r
+int print_dec(uint16_t value);\r
+int print_digit(uint8_t position, uint8_t digit);\r
+void emulate_timer_ISR(void);\r
+\r
+const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};\r
+const uint8_t en_pins[DIGITS] = {EN0_PIN, EN1_PIN, EN2_PIN, EN3_PIN};\r
+\r
+const uint8_t segment_map[16] =\r
+{\r
+ // A B C D E F G DP\r
+ 0b00000011, // 0\r
+ 0b10011111, // 1\r
+ 0b00100101, // 2\r
+ 0b00001101, // 3\r
+ 0b10011001, // 4\r
+ 0b01001001, // 5\r
+ 0b01000001, // 6\r
+ 0b00011111, // 7\r
+ 0b00000001, // 8\r
+ 0b00001001, // 9\r
+ 0b00010001, // A\r
+ 0b11000001, // b\r
+ 0b01100011, // C\r
+ 0b10000101, // d\r
+ 0b01100001, // E\r
+ 0b01110001 // F\r
+};\r
+\r
+volatile uint8_t display_value[DIGITS] = {0};\r
+volatile uint8_t current_digit = 0;\r
+\r
+void setup()\r
+{\r
+ uint8_t i;\r
+ for (i = 0; i < DIGITS; i++)\r
+ {\r
+ pinMode(en_pins[i], OUTPUT);\r
+ digitalWrite(en_pins[i], HIGH);\r
+ }\r
+ for (i = 0; i < 8; i++)\r
+ {\r
+ pinMode(segm_pins[i], OUTPUT);\r
+ digitalWrite(segm_pins[i], HIGH);\r
+ }\r
+}\r
+\r
+void loop()\r
+{\r
+ for (uint16_t cnt = (int) pow(10, DIGITS) - 1; cnt > 0; cnt--)\r
+ {\r
+ print_dec(cnt);\r
+ \r
+ // This is garbage, don't use it!\r
+ for(uint8_t i = 0; i < 10; i++)\r
+ {\r
+ delay(10);\r
+ emulate_timer_ISR();\r
+ }\r
+ }\r
+ delay(3000);\r
+}\r
+\r
+int print_dec(uint16_t value)\r
+{\r
+ if (value > (int) pow(10, DIGITS) - 1)\r
+ {\r
+ return -1;\r
+ }\r
+\r
+ for (uint8_t i = 0; i < DIGITS; i++)\r
+ {\r
+ print_digit(DIGITS - 1 - i, value % 10);\r
+ value /= 10;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+int print_digit(uint8_t position, uint8_t digit)\r
+{\r
+ if (position > DIGITS || digit > 15)\r
+ {\r
+ return -1;\r
+ }\r
+\r
+ display_value[position] = digit;\r
+\r
+ return 0;\r
+}\r
+\r
+void emulate_timer_ISR(void)\r
+{\r
+ digitalWrite(en_pins[current_digit], HIGH);\r
+\r
+ current_digit++;\r
+ if (current_digit > DIGITS - 1)\r
+ {\r
+ current_digit = 0;\r
+ }\r
+\r
+ for (uint8_t i = 0; i < 8; i++)\r
+ {\r
+ digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));\r
+ }\r
+\r
+ digitalWrite(en_pins[current_digit], LOW);\r
+}\r
--- /dev/null
+https://www.tinkercad.com/things/7eGYywVu5PG
--- /dev/null
+#include <math.h>\r
+\r
+#define A_PIN 12\r
+#define B_PIN 13\r
+#define C_PIN 7\r
+#define D_PIN 8\r
+#define E_PIN 9\r
+#define F_PIN 11\r
+#define G_PIN 10\r
+#define DP_PIN 6\r
+#define EN0_PIN 5\r
+#define EN1_PIN 4\r
+#define EN2_PIN 3\r
+#define EN3_PIN 2\r
+\r
+#define DIGITS 4\r
+\r
+int print_dec(uint16_t value);\r
+int print_digit(uint8_t position, uint8_t digit);\r
+void timer_init(void);\r
+void gpio_init(void);\r
+\r
+const uint8_t segm_pins[8] = {A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, F_PIN, G_PIN, DP_PIN};\r
+const uint8_t en_pins[DIGITS] = {EN0_PIN, EN1_PIN, EN2_PIN, EN3_PIN};\r
+\r
+const uint8_t segment_map[16] =\r
+{\r
+ // A B C D E F G DP\r
+ 0b00000011, // 0\r
+ 0b10011111, // 1\r
+ 0b00100101, // 2\r
+ 0b00001101, // 3\r
+ 0b10011001, // 4\r
+ 0b01001001, // 5\r
+ 0b01000001, // 6\r
+ 0b00011111, // 7\r
+ 0b00000001, // 8\r
+ 0b00001001, // 9\r
+ 0b00010001, // A\r
+ 0b11000001, // b\r
+ 0b01100011, // C\r
+ 0b10000101, // d\r
+ 0b01100001, // E\r
+ 0b01110001 // F\r
+};\r
+\r
+volatile uint8_t display_value[DIGITS] = {0};\r
+volatile uint8_t current_digit = 0;\r
+\r
+void setup()\r
+{\r
+ gpio_init();\r
+ timer_init();\r
+}\r
+\r
+void loop()\r
+{\r
+ for (uint16_t cnt = (int) pow(10, DIGITS) - 1; cnt > 0; cnt--)\r
+ {\r
+ print_dec(cnt);\r
+ delay(100);\r
+ }\r
+ delay(3000);\r
+}\r
+\r
+int print_dec(uint16_t value)\r
+{\r
+ if (value > (int) pow(10, DIGITS) - 1)\r
+ {\r
+ return -1;\r
+ }\r
+\r
+ for (uint8_t i = 0; i < DIGITS; i++)\r
+ {\r
+ print_digit(DIGITS - 1 - i, value % 10);\r
+ value /= 10;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+int print_digit(uint8_t position, uint8_t digit)\r
+{\r
+ if (position > DIGITS || digit > 15)\r
+ {\r
+ return -1;\r
+ }\r
+\r
+ display_value[position] = digit;\r
+\r
+ return 0;\r
+}\r
+\r
+ISR(TIMER1_OVF_vect)\r
+{\r
+ digitalWrite(en_pins[current_digit], HIGH);\r
+\r
+ current_digit++;\r
+ if (current_digit > DIGITS - 1)\r
+ {\r
+ current_digit = 0;\r
+ }\r
+\r
+ for (uint8_t i = 0; i < 8; i++)\r
+ {\r
+ digitalWrite(segm_pins[i], segment_map[display_value[current_digit]] & (128 >> i));\r
+ }\r
+\r
+ digitalWrite(en_pins[current_digit], LOW);\r
+}\r
+\r
+void gpio_init(void)\r
+{\r
+ uint8_t i;\r
+ for (i = 0; i < DIGITS; i++)\r
+ {\r
+ pinMode(en_pins[i], OUTPUT);\r
+ digitalWrite(en_pins[i], HIGH);\r
+ }\r
+ for (i = 0; i < 8; i++)\r
+ {\r
+ pinMode(segm_pins[i], OUTPUT);\r
+ digitalWrite(segm_pins[i], HIGH);\r
+ }\r
+}\r
+\r
+void timer_init(void)\r
+{\r
+ noInterrupts();\r
+ \r
+ // After clearing TCCR1B the timer is stopped\r
+ TCCR1B = 0;\r
+ TCNT1 = 0;\r
+ \r
+ TCCR1A = (1 << WGM11);\r
+ TCCR1B |= (1 << WGM12) | (1 << WGM13);\r
+ TIMSK1 = (1 << TOIE1);\r
+\r
+ // Set frequency to 1kHz\r
+ ICR1 = 1999;\r
+ TCCR1B |= (1 << CS11);\r
+\r
+ interrupts();\r
+}\r
--- /dev/null
+:100000000C945C000C9479000C9479000C947900A9
+:100010000C9479000C9479000C9479000C9479007C
+:100020000C9479000C9479000C9479000C9479006C
+:100030000C9479000C9487010C9479000C9479004D
+:100040000C943D010C9479000C9479000C94790087
+:100050000C9479000C9479000C9479000C9479003C
+:100060000C9479000C947900000000080002010053
+:100070000003040700000000000000000000000072
+:10008000250028002B0000000000240027002A0083
+:10009000040404040404040402020202020203032E
+:1000A0000303030301020408102040800102040836
+:1000B000102001020408102011241FBECFEFD8E049
+:1000C000DEBFCDBF11E0A0E0B1E0E8E9F5E002C09D
+:1000D00005900D92AC31B107D9F721E0ACE1B1E068
+:1000E00001C01D92AA32B207E1F70E94F4010C94FC
+:1000F000CA020C94000090E0FC01EC55FF4F2491E3
+:1001000080579F4FFC018491882399F090E0880FDD
+:10011000991FFC01EA57FF4FA591B491FC01E458E7
+:10012000FF4F859194918FB7F894EC91E22BEC936B
+:100130008FBF089590E0FC01E859FF4F2491FC0126
+:10014000EC55FF4F3491FC01E057FF4FE491EE2353
+:10015000C9F0222339F0233001F1A8F4213019F13C
+:10016000223029F1F0E0EE0FFF1FE458FF4FA59178
+:10017000B4918FB7F894EC91611126C030953E236D
+:100180003C938FBF08952730A9F02830C9F0243060
+:1001900049F7809180008F7D03C0809180008F7728
+:1001A00080938000DFCF84B58F7784BDDBCF84B5AB
+:1001B0008F7DFBCF8091B0008F778093B000D2CF3E
+:1001C0008091B0008F7DF9CF3E2BDACF3FB7F89406
+:1001D0008091220190912301A0912401B0912501E9
+:1001E00026B5A89B05C02F3F19F00196A11DB11D92
+:1001F0003FBFBA2FA92F982F8827BC01CD01620FCE
+:10020000711D811D911D42E0660F771F881F991F88
+:100210004A95D1F708958F929F92AF92BF92CF9255
+:10022000DF92EF92FF924B015C010E94E6006B01AE
+:100230007C010E94E6006C197D098E099F09683EC9
+:10024000734081059105A8F321E0821A9108A10865
+:10025000B10888EEC80E83E0D81EE11CF11C8114A1
+:100260009104A104B10429F7FF90EF90DF90CF90A3
+:10027000BF90AF909F908F9008951F920F920FB6EE
+:100280000F9211242F933F938F939F93AF93BF931C
+:1002900080911E0190911F01A0912001B091210138
+:1002A00030911D0123E0230F2D3758F50196A11D34
+:1002B000B11D20931D0180931E0190931F01A093F7
+:1002C0002001B09321018091220190912301A091FE
+:1002D0002401B09125010196A11DB11D8093220139
+:1002E00090932301A0932401B0932501BF91AF9176
+:1002F0009F918F913F912F910F900FBE0F901F9064
+:10030000189526E8230F0296A11DB11DD2CF1F928A
+:100310000F920FB60F921124EF92FF920F931F933B
+:100320002F933F934F935F936F937F938F939F93FD
+:10033000AF93BF93CF93DF93EF93FF93E0911C01B3
+:10034000F0E0E85EFE4F61E080810E949A008091BB
+:100350001C018F5F80931C0180911C01843010F080
+:1003600010921C0100E111E0D0E0C0E080E8E82E2E
+:10037000F12CE0911C01F0E0EA5DFE4FE081F0E03D
+:10038000E050FF4FC7010C2E02C0959587950A9447
+:10039000E2F760816823F80181918F010E949A0041
+:1003A0002196C830D10529F7E0911C01F0E0E85E04
+:1003B000FE4F60E080810E949A00FF91EF91DF91F3
+:1003C000CF91BF91AF919F918F917F916F915F91ED
+:1003D0004F913F912F911F910F91FF90EF900F90B0
+:1003E0000FBE0F901F901895789484B5826084BDDD
+:1003F00084B5816084BD85B5826085BD85B5816029
+:1004000085BD80916E00816080936E0010928100A6
+:100410008091810082608093810080918100816061
+:100420008093810080918000816080938000809122
+:10043000B10084608093B1008091B00081608093AE
+:10044000B00080917A00846080937A0080917A0075
+:10045000826080937A0080917A00816080937A0034
+:1004600080917A00806880937A001092C100C8E180
+:10047000D1E04CE1E42E41E0F42E1991812F0E944D
+:100480007B0061E0812F0E949A00EC16FD06A9F71F
+:10049000C0E1D1E038E1E32E31E0F32E1991812F54
+:1004A0000E947B0061E0812F0E949A00EC16FD06FD
+:1004B000A9F7F894109281001092850010928400A0
+:1004C00082E0809380008091810088618093810028
+:1004D00081E080936F008FEC97E09093870080938A
+:1004E00086008091810082608093810078940AE088
+:1004F00010E084E6E82EF12C98EEC92E93E0D92E78
+:1005000020E0A22E20E0B22ECFE0D7E2CE01B8014B
+:100510000E94B60280932901CB01B8010E94B60265
+:1005200080932801CE01B7010E94B602CB01B80129
+:100530000E94B60280932701CE01B6010E94B60246
+:100540006093260164E670E080E090E00E940B0179
+:100550002197E1F668EB7BE080E090E00E940B01E0
+:10056000A114B10489F20E940000CECFAA1BBB1BCC
+:1005700051E107C0AA1FBB1FA617B70710F0A61BA3
+:10058000B70B881F991F5A95A9F780959095BC01C4
+:08059000CD010895F894FFCF9E
+:10059800039F250D9949411F010911C163856171A7
+:0C05A8000C0D0708090B0A0605040302ED
+:00000001FF
--- /dev/null
+:020000040000FA
+:100000000C945C000C9479000C9479000C947900A9
+:100010000C9479000C9479000C9479000C9479007C
+:100020000C9479000C9479000C9479000C9479006C
+:100030000C9479000C9487010C9479000C9479004D
+:100040000C943D010C9479000C9479000C94790087
+:100050000C9479000C9479000C9479000C9479003C
+:100060000C9479000C947900000000080002010053
+:100070000003040700000000000000000000000072
+:10008000250028002B0000000000240027002A0083
+:10009000040404040404040402020202020203032E
+:1000A0000303030301020408102040800102040836
+:1000B000102001020408102011241FBECFEFD8E049
+:1000C000DEBFCDBF11E0A0E0B1E0E8E9F5E002C09D
+:1000D00005900D92AC31B107D9F721E0ACE1B1E068
+:1000E00001C01D92AA32B207E1F70E94F4010C94FC
+:1000F000CA020C94000090E0FC01EC55FF4F2491E3
+:1001000080579F4FFC018491882399F090E0880FDD
+:10011000991FFC01EA57FF4FA591B491FC01E458E7
+:10012000FF4F859194918FB7F894EC91E22BEC936B
+:100130008FBF089590E0FC01E859FF4F2491FC0126
+:10014000EC55FF4F3491FC01E057FF4FE491EE2353
+:10015000C9F0222339F0233001F1A8F4213019F13C
+:10016000223029F1F0E0EE0FFF1FE458FF4FA59178
+:10017000B4918FB7F894EC91611126C030953E236D
+:100180003C938FBF08952730A9F02830C9F0243060
+:1001900049F7809180008F7D03C0809180008F7728
+:1001A00080938000DFCF84B58F7784BDDBCF84B5AB
+:1001B0008F7DFBCF8091B0008F778093B000D2CF3E
+:1001C0008091B0008F7DF9CF3E2BDACF3FB7F89406
+:1001D0008091220190912301A0912401B0912501E9
+:1001E00026B5A89B05C02F3F19F00196A11DB11D92
+:1001F0003FBFBA2FA92F982F8827BC01CD01620FCE
+:10020000711D811D911D42E0660F771F881F991F88
+:100210004A95D1F708958F929F92AF92BF92CF9255
+:10022000DF92EF92FF924B015C010E94E6006B01AE
+:100230007C010E94E6006C197D098E099F09683EC9
+:10024000734081059105A8F321E0821A9108A10865
+:10025000B10888EEC80E83E0D81EE11CF11C8114A1
+:100260009104A104B10429F7FF90EF90DF90CF90A3
+:10027000BF90AF909F908F9008951F920F920FB6EE
+:100280000F9211242F933F938F939F93AF93BF931C
+:1002900080911E0190911F01A0912001B091210138
+:1002A00030911D0123E0230F2D3758F50196A11D34
+:1002B000B11D20931D0180931E0190931F01A093F7
+:1002C0002001B09321018091220190912301A091FE
+:1002D0002401B09125010196A11DB11D8093220139
+:1002E00090932301A0932401B0932501BF91AF9176
+:1002F0009F918F913F912F910F900FBE0F901F9064
+:10030000189526E8230F0296A11DB11DD2CF1F928A
+:100310000F920FB60F921124EF92FF920F931F933B
+:100320002F933F934F935F936F937F938F939F93FD
+:10033000AF93BF93CF93DF93EF93FF93E0911C01B3
+:10034000F0E0E85EFE4F61E080810E949A008091BB
+:100350001C018F5F80931C0180911C01843010F080
+:1003600010921C0100E111E0D0E0C0E080E8E82E2E
+:10037000F12CE0911C01F0E0EA5DFE4FE081F0E03D
+:10038000E050FF4FC7010C2E02C0959587950A9447
+:10039000E2F760816823F80181918F010E949A0041
+:1003A0002196C830D10529F7E0911C01F0E0E85E04
+:1003B000FE4F60E080810E949A00FF91EF91DF91F3
+:1003C000CF91BF91AF919F918F917F916F915F91ED
+:1003D0004F913F912F911F910F91FF90EF900F90B0
+:1003E0000FBE0F901F901895789484B5826084BDDD
+:1003F00084B5816084BD85B5826085BD85B5816029
+:1004000085BD80916E00816080936E0010928100A6
+:100410008091810082608093810080918100816061
+:100420008093810080918000816080938000809122
+:10043000B10084608093B1008091B00081608093AE
+:10044000B00080917A00846080937A0080917A0075
+:10045000826080937A0080917A00816080937A0034
+:1004600080917A00806880937A001092C100C8E180
+:10047000D1E04CE1E42E41E0F42E1991812F0E944D
+:100480007B0061E0812F0E949A00EC16FD06A9F71F
+:10049000C0E1D1E038E1E32E31E0F32E1991812F54
+:1004A0000E947B0061E0812F0E949A00EC16FD06FD
+:1004B000A9F7F894109281001092850010928400A0
+:1004C00082E0809380008091810088618093810028
+:1004D00081E080936F008FEC97E09093870080938A
+:1004E00086008091810082608093810078940AE088
+:1004F00010E084E6E82EF12C98EEC92E93E0D92E78
+:1005000020E0A22E20E0B22ECFE0D7E2CE01B8014B
+:100510000E94B60280932901CB01B8010E94B60265
+:1005200080932801CE01B7010E94B602CB01B80129
+:100530000E94B60280932701CE01B6010E94B60246
+:100540006093260164E670E080E090E00E940B0179
+:100550002197E1F668EB7BE080E090E00E940B01E0
+:10056000A114B10489F20E940000CECFAA1BBB1BCC
+:1005700051E107C0AA1FBB1FA617B70710F0A61BA3
+:10058000B70B881F991F5A95A9F780959095BC01C4
+:10059000CD010895F894FFCF039F250D9949411F80
+:1005A000010911C1638561710C0D0708090B0A0669
+:0405B0000504030239
+:107E0000112484B714BE81FFF0D085E080938100F7
+:107E100082E08093C00088E18093C10086E0809377
+:107E2000C20080E18093C4008EE0C9D0259A86E02C
+:107E300020E33CEF91E0309385002093840096BBD3
+:107E4000B09BFECF1D9AA8958150A9F7CC24DD24C4
+:107E500088248394B5E0AB2EA1E19A2EF3E0BF2EE7
+:107E6000A2D0813461F49FD0082FAFD0023811F036
+:107E7000013811F484E001C083E08DD089C08234E0
+:107E800011F484E103C0853419F485E0A6D080C0E4
+:107E9000853579F488D0E82EFF2485D0082F10E0AE
+:107EA000102F00270E291F29000F111F8ED06801E7
+:107EB0006FC0863521F484E090D080E0DECF843638
+:107EC00009F040C070D06FD0082F6DD080E0C81688
+:107ED00080E7D80618F4F601B7BEE895C0E0D1E017
+:107EE00062D089930C17E1F7F0E0CF16F0E7DF06D8
+:107EF00018F0F601B7BEE89568D007B600FCFDCFD4
+:107F0000A601A0E0B1E02C9130E011968C91119780
+:107F100090E0982F8827822B932B1296FA010C0160
+:107F200087BEE89511244E5F5F4FF1E0A038BF0790
+:107F300051F7F601A7BEE89507B600FCFDCF97BE46
+:107F4000E89526C08437B1F42ED02DD0F82E2BD052
+:107F50003CD0F601EF2C8F010F5F1F4F84911BD097
+:107F6000EA94F801C1F70894C11CD11CFA94CF0C13
+:107F7000D11C0EC0853739F428D08EE10CD085E9AC
+:107F80000AD08FE07ACF813511F488E018D01DD067
+:107F900080E101D065CF982F8091C00085FFFCCF94
+:107FA0009093C60008958091C00087FFFCCF809118
+:107FB000C00084FD01C0A8958091C6000895E0E648
+:107FC000F0E098E1908380830895EDDF803219F02E
+:107FD00088E0F5DFFFCF84E1DECF1F93182FE3DFCA
+:107FE0001150E9F7F2DF1F91089580E0E8DFEE27F6
+:047FF000FF270994CA
+:027FFE00040479
+:00000001FF
--- /dev/null
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\r
+<WORKSPACE>\r
+ <FRAME activewindow="0">\r
+ <PLACEMENT>2c0000000200000003000000ffffffffffffffffffffffffffffffffab0000000d000000d606000004040000</PLACEMENT>\r
+ <WINDOW type="default" module="ISIS"/>\r
+ <WINDOW type="device" module="LIBMAN"/>\r
+ </FRAME>\r
+ <MODULE name="VSMDEBUG">\r
+ <PWI>\r
+ <POPUP w="800" x="38" flags="00000002" y="129" h="200" pid="0" iid="-1">\r
+ <PROPERTIES>\r
+ <ITEM name="Message Column Width">542</ITEM>\r
+ <ITEM name="ShowGrid">No</ITEM>\r
+ <ITEM name="Source Column Width">100</ITEM>\r
+ <ITEM name="Time Column Width">120</ITEM>\r
+ <ITEM name="Version">100</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="350" x="58" flags="00000032" y="149" h="200" pid="1" iid="-1">\r
+ <PROPERTIES>\r
+ <ITEM name="Address Column Width">83</ITEM>\r
+ <ITEM name="AutoResize">No</ITEM>\r
+ <ITEM name="Gridlines">Yes</ITEM>\r
+ <ITEM name="Name Column Width">83</ITEM>\r
+ <ITEM name="ShowAddresses">Yes</ITEM>\r
+ <ITEM name="ShowPreviousValues">No</ITEM>\r
+ <ITEM name="ShowTypes">No</ITEM>\r
+ <ITEM name="ShowWatchPoint">Yes</ITEM>\r
+ <ITEM name="TriggerMode">0</ITEM>\r
+ <ITEM name="Value Column Width">83</ITEM>\r
+ <ITEM name="Version">100</ITEM>\r
+ <ITEM name="Watch Expression Column Width">83</ITEM>\r
+ <ITEM name="nItems">0</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="226" x="78" flags="00000008" y="169" h="215" pid="3" iid="1">\r
+ <PROPERTIES/>\r
+ </POPUP>\r
+ <POPUP w="8" x="98" flags="0000000a" y="189" h="1" pid="10" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000000</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="8" x="118" flags="0000000a" y="209" h="32" pid="6" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000000</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="16" x="138" flags="0000000a" y="229" h="32" pid="7" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000000</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="16" x="158" flags="80000000" y="249" h="32" pid="14" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000000</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="16" x="178" flags="0000000a" y="269" h="32" pid="4" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000100</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="16" x="198" flags="0000000a" y="289" h="8" pid="13" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000020</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ </PWI>\r
+ </MODULE>\r
+</WORKSPACE>\r
--- /dev/null
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<WORKSPACE>
+ <FRAME activewindow="0">
+ <PLACEMENT>2c00000002000000030000000083ffff0083ffffffffffffffffffffb20000000c000000ce060000fa030000</PLACEMENT>
+ <WINDOW type="default" module="ISIS"/>
+ </FRAME>
+ <MODULE name="VSMDEBUG">
+ <PWI>
+ <POPUP w="400" x="5" flags="00000002" y="87" h="100" pid="0" iid="-1">
+ <PROPERTIES>
+ <ITEM name="Message Column Width">142</ITEM>
+ <ITEM name="ShowGrid">No</ITEM>
+ <ITEM name="Source Column Width">100</ITEM>
+ <ITEM name="Time Column Width">120</ITEM>
+ <ITEM name="Version">100</ITEM>
+ </PROPERTIES>
+ </POPUP>
+ <POPUP w="350" x="5" flags="00000032" y="87" h="100" pid="1" iid="-1">
+ <PROPERTIES>
+ <ITEM name="Address Column Width">83</ITEM>
+ <ITEM name="AutoResize">No</ITEM>
+ <ITEM name="Gridlines">Yes</ITEM>
+ <ITEM name="Name Column Width">83</ITEM>
+ <ITEM name="ShowAddresses">Yes</ITEM>
+ <ITEM name="ShowPreviousValues">No</ITEM>
+ <ITEM name="ShowTypes">No</ITEM>
+ <ITEM name="ShowWatchPoint">Yes</ITEM>
+ <ITEM name="TriggerMode">0</ITEM>
+ <ITEM name="Value Column Width">83</ITEM>
+ <ITEM name="Version">100</ITEM>
+ <ITEM name="Watch Expression Column Width">83</ITEM>
+ <ITEM name="nItems">0</ITEM>
+ </PROPERTIES>
+ </POPUP>
+ <POPUP w="30" x="5" flags="00000008" y="87" h="16" pid="3" iid="1">
+ <PROPERTIES/>
+ </POPUP>
+ <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="10" iid="1">
+ <PROPERTIES>
+ <ITEM name="DataType">2</ITEM>
+ <ITEM name="DispChars">Yes</ITEM>
+ <ITEM name="DispFormat">2</ITEM>
+ <ITEM name="ShowChanges">Yes</ITEM>
+ <ITEM name="ShowToolTips">Yes</ITEM>
+ <ITEM name="TopLineAddress">00000000</ITEM>
+ </PROPERTIES>
+ </POPUP>
+ <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="6" iid="1">
+ <PROPERTIES>
+ <ITEM name="DataType">2</ITEM>
+ <ITEM name="DispChars">Yes</ITEM>
+ <ITEM name="DispFormat">2</ITEM>
+ <ITEM name="ShowChanges">Yes</ITEM>
+ <ITEM name="ShowToolTips">Yes</ITEM>
+ <ITEM name="TopLineAddress">00000000</ITEM>
+ </PROPERTIES>
+ </POPUP>
+ <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="7" iid="1">
+ <PROPERTIES>
+ <ITEM name="DataType">2</ITEM>
+ <ITEM name="DispChars">Yes</ITEM>
+ <ITEM name="DispFormat">2</ITEM>
+ <ITEM name="ShowChanges">Yes</ITEM>
+ <ITEM name="ShowToolTips">Yes</ITEM>
+ <ITEM name="TopLineAddress">00000000</ITEM>
+ </PROPERTIES>
+ </POPUP>
+ <POPUP w="16" x="188" flags="00000000" y="256" h="32" pid="14" iid="1">
+ <PROPERTIES>
+ <ITEM name="DataType">2</ITEM>
+ <ITEM name="DispChars">Yes</ITEM>
+ <ITEM name="DispFormat">2</ITEM>
+ <ITEM name="ShowChanges">Yes</ITEM>
+ <ITEM name="ShowToolTips">Yes</ITEM>
+ <ITEM name="TopLineAddress">00000000</ITEM>
+ </PROPERTIES>
+ </POPUP>
+ <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="4" iid="1">
+ <PROPERTIES>
+ <ITEM name="DataType">2</ITEM>
+ <ITEM name="DispChars">Yes</ITEM>
+ <ITEM name="DispFormat">2</ITEM>
+ <ITEM name="ShowChanges">Yes</ITEM>
+ <ITEM name="ShowToolTips">Yes</ITEM>
+ <ITEM name="TopLineAddress">00000100</ITEM>
+ </PROPERTIES>
+ </POPUP>
+ <POPUP w="1" x="5" flags="0000000a" y="87" h="1" pid="13" iid="1">
+ <PROPERTIES>
+ <ITEM name="DataType">2</ITEM>
+ <ITEM name="DispChars">Yes</ITEM>
+ <ITEM name="DispFormat">2</ITEM>
+ <ITEM name="ShowChanges">Yes</ITEM>
+ <ITEM name="ShowToolTips">Yes</ITEM>
+ <ITEM name="TopLineAddress">00000020</ITEM>
+ </PROPERTIES>
+ </POPUP>
+ </PWI>
+ </MODULE>
+</WORKSPACE>
--- /dev/null
+#define LATCH_PIN 4
+#define CLK_PIN 7
+#define SDI_PIN 8
+
+int print_digit(uint8_t segment, uint8_t value);
+
+// Segment map to select number 0 to F
+const uint8_t SEGMENT_MAP[16] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E};
+// Byte map to select digit 0 to 3
+const uint8_t SEGMENT_SELECT[4] = {0xF1, 0xF2, 0xF4, 0xF8};
+
+void setup()
+{
+ pinMode(LATCH_PIN, OUTPUT);
+ pinMode(CLK_PIN, OUTPUT);
+ pinMode(SDI_PIN, OUTPUT);
+ digitalWrite(LATCH_PIN, LOW);
+ digitalWrite(CLK_PIN, LOW);
+ digitalWrite(SDI_PIN, LOW);
+}
+
+void loop()
+{
+ print_digit(0, 5);
+ print_digit(1, 6);
+ print_digit(2, 7);
+ print_digit(3, 9);
+}
+
+// Write a decimal number between 0 and 9 to one of the 4 digits of the display
+int print_digit(uint8_t segment, uint8_t value)
+{
+ if (value > 15 || segment > 3)
+ {
+ return -1;
+ }
+
+ shiftOut(SDI_PIN, CLK_PIN, MSBFIRST, SEGMENT_MAP[value]);
+ shiftOut(SDI_PIN, CLK_PIN, MSBFIRST, SEGMENT_SELECT[segment] );
+ digitalWrite(LATCH_PIN, HIGH);
+ digitalWrite(LATCH_PIN, LOW);
+
+ return 0;
+}
+++ /dev/null
-#define LDR A0
-
-uint16_t value = 0;
-
-void setup()
-{
- pinMode(A0, INPUT);
- Serial.begin(9600);
-}
-
-void loop()
-{
- value = analogRead(LDR);
- Serial.println(value);
- delay(100);
-}
+++ /dev/null
-#include <Adafruit_NeoPixel.h>
-#include <inttypes.h>
-
-#define ROWS 8
-#define COLS 32
-#define NUM_PIXELS (ROWS * COLS)
-#define PPM_HEADER_LENGHT 12
-#define BIG_IMAGE_FILE_SIZE 780
-#define DIMM 4
-
-#define Y_U_NO_WORK
-//#define STM32
-
-#ifdef STM32
-#define LED_PIN PA2
-#else
-#define LED_PIN 12
-#endif
-
-int render_image(uint8_t buff[ROWS][COLS][3], const uint8_t image[]);
-int display_rgb(uint8_t buff[ROWS][COLS][3]);
-int display_rgb_direct(const uint8_t image[]);
-
-static const uint8_t big_image_data[BIG_IMAGE_FILE_SIZE] =
-{
- 0x50, 0x36, 0x0a, 0x33, 0x32, 0x20, 0x38, 0x0a, 0x32, 0x35, 0x35, 0x0a,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00,
- 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00,
- 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-Adafruit_NeoPixel led_matrix(NUM_PIXELS, LED_PIN, NEO_GRB);
-
-void setup()
-{
- led_matrix.begin();
- led_matrix.fill(led_matrix.Color(0, 20 / DIMM, 6 / DIMM));
-}
-
-void loop()
-{
- #ifdef Y_U_NO_WORK
-
- volatile uint8_t hax[27] = {0}; // Interesting values: 19, 20-31, 32, 50
- uint8_t frame_buffer[ROWS][COLS][3] = {{{0}}};
-
- render_image(frame_buffer, big_image_data);
- display_rgb(frame_buffer);
-
- #else
-
- display_rgb_direct(big_image_data);
-
- #endif
-}
-
-int render_image(uint8_t buff[ROWS][COLS][3], const uint8_t image[])
-{
- size_t row_offset, col_offset;
-
- if (buff == NULL || image == NULL)
- return -1;
-
- for (uint8_t row = 0; row < ROWS; row++)
- {
- row_offset = row * COLS * 3;
- for (uint8_t col = 0; col < COLS; col++)
- {
- col_offset = col * 3;
- for (uint8_t i = 0; i < 3; i++)
- {
- buff[row][col][i] = image[PPM_HEADER_LENGHT + row_offset + col_offset + i];
- }
- }
- }
-
- return 0;
-}
-
-int display_rgb(uint8_t buff[ROWS][COLS][3])
-{
- if (buff == NULL)
- return -1;
-
- for (uint8_t col = 0; col < COLS; col += 2)
- {
- for (uint8_t row = 0; row < ROWS; row++)
- {
- if (buff[row][col][0] || buff[row][col][1] || buff[row][col][2])
- {
- led_matrix.setPixelColor(col * ROWS + row,
- led_matrix.Color(buff[row][col][0] / DIMM,
- buff[row][col][1] / DIMM,
- buff[row][col][2] / DIMM));
- }
- }
- }
- for (uint8_t col = 1; col < COLS; col += 2)
- {
- for (uint8_t row = 0; row < ROWS; row++)
- {
- if (buff[row][col][0] || buff[row][col][1] || buff[row][col][2])
- {
- led_matrix.setPixelColor((col + 1) * ROWS - row - 1,
- led_matrix.Color(buff[row][col][0] / DIMM,
- buff[row][col][1] / DIMM,
- buff[row][col][2] / DIMM));
- }
- }
- }
- led_matrix.show();
-
- return 0;
-}
-
-int display_rgb_direct(const uint8_t image[])
-{
- size_t row_offset, col_offset, offset;
-
- if (image == NULL)
- return -1;
-
- for (uint8_t col = 0; col < COLS; col += 2)
- {
- col_offset = col * 3;
- for (uint8_t row = 0; row < ROWS; row++)
- {
- row_offset = row * COLS * 3;
- offset = PPM_HEADER_LENGHT + row_offset + col_offset;
- if (image[offset] || image[offset + 1] || image[offset + 2])
- {
- led_matrix.setPixelColor(col * ROWS + row,
- led_matrix.Color(image[offset] / DIMM,
- image[offset + 1] / DIMM,
- image[offset + 2] / DIMM));
- }
- }
- }
- for (uint8_t col = 1; col < COLS; col += 2)
- {
- col_offset = col * 3;
- for (uint8_t row = 0; row < ROWS; row++)
- {
- row_offset = row * COLS * 3;
- offset = PPM_HEADER_LENGHT + row_offset + col_offset;
- if (image[offset] || image[offset + 1] || image[offset + 2])
- {
- led_matrix.setPixelColor((col + 1) * ROWS - row - 1,
- led_matrix.Color(image[offset] / DIMM,
- image[offset + 1] / DIMM,
- image[offset + 2] / DIMM));
- }
- }
- }
- led_matrix.show();
-
- return 0;
-}
+++ /dev/null
-https://www.tinkercad.com/things/eOSmRi4TA7z-bigledstrip
+++ /dev/null
-#include <Adafruit_NeoPixel.h>
-
-#define NUM_PIXELS 6
-#define MIN_DELAY 30
-
-#define TOP_ROW 2
-#define MID_ROW 3
-#define BOT_ROW 4
-#define UP_BUTTON 6
-#define DOWN_BUTTON 5
-#define NOISE A0
-
-#define PLAYER 1
-#define CAR 2
-#define EMPTY 0
-#define CRASH 3
-
-Adafruit_NeoPixel top_row(NUM_PIXELS, TOP_ROW, NEO_GRB);
-Adafruit_NeoPixel mid_row(NUM_PIXELS, MID_ROW, NEO_GRB);
-Adafruit_NeoPixel bot_row(NUM_PIXELS, BOT_ROW, NEO_GRB);
-
-// Video RAM - every element corresponds to one pixel
-int vram[3][NUM_PIXELS] = {{0}}; // 2 - TOP, 1 - MID, 0 - BOT
-int player_pos = 1;
-int next_car_in = 1;
-int delay_time = 500;
-int crashed = 0;
-
-void setup()
-{
- pinMode(TOP_ROW, OUTPUT);
- pinMode(MID_ROW, OUTPUT);
- pinMode(BOT_ROW, OUTPUT);
- pinMode(UP_BUTTON, INPUT);
- pinMode(DOWN_BUTTON, INPUT);
- pinMode(NOISE, INPUT);
-
- // LED strip initialization
- top_row.begin();
- mid_row.begin();
- bot_row.begin();
-
- // set the seed for the random number generator
- int seed = analogRead(NOISE) * 42;
- randomSeed(seed);
-
- Serial.begin(9600);
-}
-
-void loop()
-{
- int i;
- int new_car;
-
- // update player position
- if (digitalRead(UP_BUTTON) == HIGH)
- {
- player_pos++;
- }
- else if (digitalRead(DOWN_BUTTON) == HIGH)
- {
- player_pos--;
- }
- if (player_pos > 2)
- {
- player_pos = 2;
- }
- else if (player_pos < 0)
- {
- player_pos = 0;
- }
-
- // draw the player
- for (i = 0; i < 3; i++)
- {
- if (player_pos == i)
- {
- // detect collision
- if (vram[i][1] == CAR)
- {
- vram[i][0] = CRASH;
- crashed = 1;
- }
- else
- {
- vram[i][0] = PLAYER;
- }
- }
- else
- {
- vram[i][0] = vram[i][1];
- }
- }
-
- // move everything one pixel to the left
- for (i = 1; i < (NUM_PIXELS - 1); i++)
- {
- vram[0][i] = vram[0][i + 1];
- vram[1][i] = vram[1][i + 1];
- vram[2][i] = vram[2][i + 1];
- }
-
- // generate next car
- for (i = 0; i < 3; i++)
- {
- vram[i][NUM_PIXELS - 1] = EMPTY;
- }
- next_car_in--;
- if (next_car_in == 0)
- {
- new_car = random(3);
- vram[new_car][NUM_PIXELS - 1] = CAR;
- next_car_in = 3;
- }
-
- // render the image
- // Note: this was originally made for a couple of younger kids who hadn't learned about switch-case yet
- for (i = 0; i < NUM_PIXELS; i++)
- {
- if (vram[0][i] == EMPTY)
- {
- bot_row.setPixelColor(i, bot_row.Color(0, 0, 0));
- }
- else if (vram[0][i] == CAR)
- {
- bot_row.setPixelColor(i, bot_row.Color(0, 0, 255));
- }
- else if (vram[0][i] == PLAYER)
- {
- bot_row.setPixelColor(i, bot_row.Color(0, 255, 0));
- }
- else if (vram[0][i] == CRASH)
- {
- bot_row.setPixelColor(i, bot_row.Color(255, 0, 0));
- }
-
- if (vram[1][i] == EMPTY)
- {
- mid_row.setPixelColor(i, mid_row.Color(0, 0, 0));
- }
- else if (vram[1][i] == CAR)
- {
- mid_row.setPixelColor(i, mid_row.Color(0, 0, 255));
- }
- else if (vram[1][i] == PLAYER)
- {
- mid_row.setPixelColor(i, mid_row.Color(0, 255, 0));
- }
- else if (vram[1][i] == CRASH)
- {
- mid_row.setPixelColor(i, mid_row.Color(255, 0, 0));
- }
-
- if (vram[2][i] == EMPTY)
- {
- top_row.setPixelColor(i, top_row.Color(0, 0, 0));
- }
- else if (vram[2][i] == CAR)
- {
- top_row.setPixelColor(i, top_row.Color(0, 0, 255));
- }
- else if (vram[2][i] == PLAYER)
- {
- top_row.setPixelColor(i, top_row.Color(0, 255, 0));
- }
- else if (vram[2][i] == CRASH)
- {
- top_row.setPixelColor(i, top_row.Color(255, 0, 0));
- }
- }
- top_row.show();
- mid_row.show();
- bot_row.show();
- Serial.println(delay_time);
- // stop the game if crashed
- if (crashed)
- {
- while (1);
- }
- // delay before the next frame
- else
- {
- delay(delay_time);
- }
- // slowly make the game faster
- if (delay_time > MIN_DELAY)
- {
- delay_time--;
- }
-}
+++ /dev/null
-https://www.tinkercad.com/things/0J1F6FpWf9y
+++ /dev/null
-#include <Servo.h>
-
-#define DRV_A1 6
-#define DRV_A2 5
-#define EN_L 7
-#define DRV_A3 9
-#define DRV_A4 11
-#define EN_R 4
-#define SERVO_PIN 10
-
-Servo aservo;
-
-void forward(uint8_t speed);
-void reverse(uint8_t speed);
-void turn_left(uint8_t speed);
-void turn_right(uint8_t speed);
-
-void setup()
-{
- pinMode(DRV_A1, OUTPUT);
- pinMode(DRV_A2, OUTPUT);
- pinMode(EN_L, OUTPUT);
- digitalWrite(DRV_A1, LOW);
- digitalWrite(DRV_A2, LOW);
- digitalWrite(EN_L, HIGH);
-
- pinMode(DRV_A3, OUTPUT);
- pinMode(DRV_A4, OUTPUT);
- pinMode(EN_R, OUTPUT);
- digitalWrite(DRV_A3, LOW);
- digitalWrite(DRV_A4, LOW);
- digitalWrite(EN_R, HIGH);
-
- aservo.attach(SERVO_PIN);
-}
-
-void loop()
-{
- /*
- digitalWrite(DRV_A1, HIGH);
- analogWrite(DRV_A2, 128);
- digitalWrite(EN_L, HIGH);
- */
-
- //aservo.write(90);
-
- /*
- for (uint8_t i = 0; i < 4; i++)
- {
- forward(255);
- delay(5000);
- turn_right(128);
- delay(1000);
- }
- digitalWrite(EN_L, LOW);
- digitalWrite(EN_R, LOW);
- */
-}
-
-void forward(uint8_t speed)
-{
- analogWrite(DRV_A1, speed);
- digitalWrite(DRV_A2, LOW);
- analogWrite(DRV_A3, speed);
- digitalWrite(DRV_A4, LOW);
-}
-
-void reverse(uint8_t speed)
-{
- digitalWrite(DRV_A1, LOW);
- analogWrite(DRV_A2, speed);
- digitalWrite(DRV_A3, LOW);
- analogWrite(DRV_A4, speed);
-}
-
-void turn_left(uint8_t speed)
-{
- digitalWrite(DRV_A1, LOW);
- analogWrite(DRV_A2, speed);
- analogWrite(DRV_A3, speed);
- digitalWrite(DRV_A4, LOW);
-}
-
-void turn_right(uint8_t speed)
-{
- analogWrite(DRV_A1, speed);
- digitalWrite(DRV_A2, LOW);
- digitalWrite(DRV_A3, LOW);
- analogWrite(DRV_A4, speed);
-}
-
-void stop_motors()
-{
- digitalWrite(DRV_A1, LOW);
- digitalWrite(DRV_A2, LOW);
- digitalWrite(DRV_A3, LOW);
- digitalWrite(DRV_A4, LOW);
-}
+++ /dev/null
-https://www.tinkercad.com/things/8ef4pvh4R76
+++ /dev/null
-#define DRV_IN1 11
-#define DRV_IN2 10
-#define DRV_EN 12
-#define POT A0
-
-void setup()
-{
- pinMode(DRV_IN1, OUTPUT);
- pinMode(DRV_IN2, OUTPUT);
- pinMode(DRV_EN, OUTPUT);
- pinMode(POT, INPUT);
- digitalWrite(DRV_IN1, LOW);
- digitalWrite(DRV_IN2, LOW);
- digitalWrite(DRV_EN, HIGH);
-}
-
-void loop()
-{
- // Instead of /4, map() or >>2 can be used.
- analogWrite(DRV_IN1, analogRead(POT) / 4);
-}
+++ /dev/null
-https://www.tinkercad.com/things/3tiT8HWMh1X-dcmotorspeedcontrol
+++ /dev/null
-#include <Adafruit_NeoPixel.h>
-#define NUM_PIXELS 10
-#define PIN 12
-Adafruit_NeoPixel strip(NUM_PIXELS, PIN, NEO_GRB);
-
-#define BTN 2
-
-uint8_t colorToggle = 0;
-
-void changeColor();
-
-#define A1 5
-#define A2 6
-#define EN1 13
-
-#define POT A3
-
-uint16_t count = 0;
-
-void setup()
-{
- strip.begin();
- //changeColor();
- pinMode(2, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(BTN), changeColor, FALLING);
-
- pinMode(POT, INPUT);
- pinMode(A1, OUTPUT);
- pinMode(A2, OUTPUT);
- pinMode(EN1, OUTPUT);
- digitalWrite(EN1, HIGH);
-
- TCCR1A = 0;
- TCCR1B = 0;
- TCNT1 = 0;
- OCR1A = 0;
- OCR1B = 0;
- ICR1 = 0;
- TIMSK1 = 0;
- TIFR1 = 0;
-
- TCCR1A |= (1 << WGM11) | (1 << COM1B1);
- TCCR1B |= (1 << WGM12) | (1 << WGM13);
- OCR1B = 781;
- ICR1 = 1249;
-
- TCCR1B |= (1 << CS10) | (1 << CS11);
-
- //Serial.begin(115200);
-}
-
-void loop()
-{
- uint16_t pot_value = analogRead(POT);
- pot_value = map(pot_value, 0, 1023, 0, 255);
- analogWrite(A1, pot_value);
- digitalWrite(A2, LOW);
-}
-
-void changeColor()
-{
- if (colorToggle == 1)
- {
- strip.setPixelColor(2, strip.Color(0, 255, 0));
- colorToggle = 0;
- }
- else
- {
- strip.setPixelColor(2, strip.Color(255, 255, 255));
- colorToggle = 1;
- }
- strip.show();
-}
-
-ISR(TIMER1_OVF_vect)
-{
- count++;
- //Serial.println(count);
-}
+++ /dev/null
-// Slightly different implementation
-https://www.tinkercad.com/things/ffni7S7fML6
+++ /dev/null
-#define BTN 2
-#define LED 5
-
-byte stateON = false;
-uint8_t count = 0;
-
-void setup()
-{
- pinMode(BTN, INPUT);
- pinMode(LED, OUTPUT);
-}
-
-void loop()
-{
- if(digitalRead(BTN) == 0)
- {
- stateON = true;
- }
-
- if(stateON == true)
- {
- digitalWrite(LED, HIGH);
- delay(500);
- digitalWrite(LED, LOW);
- delay(500);
- count++;
- if(count >= 5)
- {
- stateON = false;
- }
- }
-}
+++ /dev/null
-#define LED PB5 // LED is connected to digital pin 13
-#define BTN PD2 // Button is connected to digital pin 2
-
-void setup()
-{
- // PB5 is OUTPUT
- DDRB |= (1 << PB5); //0b00100000; // 0x20;
- // PD2 is INPUT
- DDRD &= ~(1 << BTN);
- // PD2 PULLUP turn on
- PORTD |= (1 << BTN);
-
- cli(); // Disable Global Interrupts
-
- // Set INT0 mode to FALLING
- EICRA = 0;
- EICRA |= (1 << ISC01);
- // Enable INT0 interrupt
- EIMSK = 0;
- EIMSK |= (1 << INT0);
-
- sei(); // Enable Global Interrupts
-}
-
-void loop()
-{
- // Empty
-}
-
-ISR(INT0_vect)
-{
- PORTB ^= (1 << PB5); // Toggle LED
-}
+++ /dev/null
-#define LED 12
-#define BTN 2
-
-// Define interrupt flag variable - must be volatile
-//volatile uint8_t state = 1;
-
-void setup() {
- pinMode(LED,OUTPUT);
- pinMode(BTN,INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(BTN), ISR_Task, FALLING);
-}
-
-void loop() {
- /*
- // Read the interrupt flag and do something
- if(state == 1)
- {
- digitalWrite(LED, !digitalRead(LED));
- delay(100);
- state = 0;
- }
- */
-}
-
-// Handler for the INT0 external interrupt
-void ISR_Task() {
- //state = 1; // Better to only set a flag so that the ISR is short and fast
- //delay(2000); // Show that delay doesn't work
- digitalWrite(LED, !digitalRead(LED));
-}
--- /dev/null
+#define LED_ROW1 11 // Active HIGH | Inactive LOW
+#define LED_ROW2 10 // Active HIGH | Inactive LOW
+#define LED_ROW3 9 // Active HIGH | Inactive LOW
+#define LED_COL1 8 // Active LOW | Inactive HIGH
+#define LED_COL2 7 // Active LOW | Inactive HIGH
+#define LED_COL3 6 // Active LOW | Inactive HIGH
+
+#define BTN_ROW1 A3 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_ROW2 A4 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_ROW3 A5 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_COL1 A0 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_COL2 A1 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_COL3 A2 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+
+const uint8_t led_col[3] = {LED_COL1, LED_COL2, LED_COL3};
+const uint8_t led_row[3] = {LED_ROW1, LED_ROW2, LED_ROW3};
+
+const uint8_t btn_col[3] = {BTN_COL1, BTN_COL2, BTN_COL3};
+const uint8_t btn_row[3] = {BTN_ROW1, BTN_ROW2, BTN_ROW3};
+
+uint8_t state_1[3][3] =
+{
+ {0, 0, 0},
+ {0, 0, 0},
+ {0, 0, 0}
+};
+
+void setup()
+{
+ int i = 0;
+
+ for (i = 0; i < 3; i++)
+ {
+ pinMode(led_row[i], OUTPUT);
+ digitalWrite(led_row[i], LOW);
+ pinMode(led_col[i], OUTPUT);
+ digitalWrite(led_col[i], HIGH);
+
+ pinMode(btn_row[i], INPUT_PULLUP);
+ pinMode(btn_col[i], INPUT_PULLUP);
+ }
+}
+
+void loop()
+{
+ // Button scan
+ for (byte col = 0; col < 3; col++)
+ {
+ pinMode(btn_col[col], OUTPUT);
+ digitalWrite(btn_col[col], LOW);
+ for (byte row = 0; row < 3; row++)
+ {
+ state_1[row][col] = !digitalRead(btn_row[row]);
+ }
+ pinMode(btn_col[col], INPUT_PULLUP);
+ }
+
+ // Transpose
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = i + 1; j < 3; j++)
+ {
+ int temp;
+ temp = state_1[i][j];
+ state_1[i][j] = state_1[j][i];
+ state_1[j][i] = temp;
+ }
+ }
+
+ // LED update
+ for (byte col = 0; col < 3; col++)
+ {
+ for (byte row = 0; row < 3; row++)
+ {
+ digitalWrite(led_row[row], state_1[row][col]);
+ }
+ digitalWrite(led_col[col], LOW);
+ delay(5);
+ digitalWrite(led_col[col], HIGH);
+ for (byte row = 0; row < 3; row++)
+ {
+ digitalWrite(led_row[row], LOW);
+ }
+ }
+}
--- /dev/null
+https://www.tinkercad.com/things/bJ9mxNp3wXG
--- /dev/null
+#define BTN 2
+#define LED 5
+
+byte stateON = false;
+uint8_t count = 0;
+
+void setup()
+{
+ pinMode(BTN, INPUT);
+ pinMode(LED, OUTPUT);
+}
+
+void loop()
+{
+ if(digitalRead(BTN) == 0)
+ {
+ stateON = true;
+ }
+
+ if(stateON == true)
+ {
+ digitalWrite(LED, HIGH);
+ delay(500);
+ digitalWrite(LED, LOW);
+ delay(500);
+ count++;
+ if(count >= 5)
+ {
+ stateON = false;
+ }
+ }
+}
--- /dev/null
+void setup() {
+ DDRB |= (1 << PB5); // Set digital pin 13 (Port B Pin 5) to output
+}
+
+void loop() {
+ PORTB |= (1 << PB5); // Set digital pin 13 (Port B Pin 5) high
+ _delay_ms(500); // wait 500ms
+ PORTB &= ~(1 << PB5); // Set digital pin 13 (Port B Pin 5) low
+ _delay_ms(500); // wait 500ms
+
+ //PORTB ^= (1 << PB5); // Toggle digital pin 13 (Port B Pin 5)
+}
+++ /dev/null
-// Generate an LED gamma-correction table for Arduino sketches.
-// Copy-and-paste the program's output into an Arduino sketch.
-
-float gamma = 2.2; // Correction factor
-uint8_t max_in = 255; // Top end of INPUT range
-uint8_t max_out = 255; // Top end of OUTPUT range
-
-uint8_t temp = 0;
-
-void setup() {
- Serial.begin(9600);
- Serial.print("const uint8_t PROGMEM gamma[] = {");
- for (int i = 0; i <= max_in; i++) {
- if (i > 0) Serial.print(',');
- if ((i & 15) == 0) Serial.print("\n ");
- temp = (uint8_t)(pow((float)i / (float)max_in, gamma) * max_out + 0.5);
- Serial.print(temp);
- }
- Serial.println("\n };");
-}
-
-void loop() {
-
-}
--- /dev/null
+#include <Wire.h>
+
+#define INT_SLAVE1_PIN 3
+#define INT_SLAVE2_PIN 2
+
+#define SLAVE1_ADDRESS 0x09
+#define SLAVE2_ADDRESS 0x0A
+
+size_t i2c_write(uint8_t address, void *data, size_t size);
+size_t i2c_read(uint8_t address, void *data, size_t size);
+void slave1_interrupt(void);
+void slave2_interrupt(void);
+
+volatile bool new_data1 = false;
+volatile bool new_data2 = false;
+
+void setup()
+{
+ Wire.begin();
+ Serial.begin(9600);
+ pinMode(INT_SLAVE1_PIN, INPUT);
+ pinMode(INT_SLAVE2_PIN, INPUT);
+ attachInterrupt(digitalPinToInterrupt(INT_SLAVE1_PIN), slave1_interrupt, RISING);
+ attachInterrupt(digitalPinToInterrupt(INT_SLAVE2_PIN), slave2_interrupt, RISING);
+}
+
+void loop()
+{
+ uint8_t dip_sw;
+
+ if (new_data1)
+ {
+ i2c_read(SLAVE1_ADDRESS, &dip_sw, sizeof(dip_sw));
+ Serial.print("From slave 1: ");
+ Serial.println(dip_sw);
+ new_data1 = false;
+ }
+ if (new_data2)
+ {
+ i2c_read(SLAVE2_ADDRESS, &dip_sw, sizeof(dip_sw));
+ Serial.print("From slave 2: ");
+ Serial.println(dip_sw);
+ new_data2 = false;
+ }
+}
+
+size_t i2c_write(uint8_t address, void *data, size_t size)
+{
+ int error_code;
+ size_t bytes_written;
+
+ Wire.beginTransmission(address);
+ bytes_written = Wire.write((uint8_t *) data, size);
+ error_code = Wire.endTransmission();
+
+ return error_code ? 0: bytes_written;
+}
+
+size_t i2c_read(uint8_t address, void *data, size_t size)
+{
+ size_t bytes_received = Wire.requestFrom(address, size);
+
+ if (bytes_received == size)
+ {
+ for (size_t i = 0; i < size; i++)
+ {
+ ((uint8_t *) data)[i] = Wire.read();
+ }
+ }
+
+ return bytes_received;
+}
+
+void slave1_interrupt(void)
+{
+ new_data1 = true;
+}
+
+void slave2_interrupt(void)
+{
+ new_data2 = true;
+}
\ No newline at end of file
--- /dev/null
+#include <Wire.h>
+
+#define MASTER_INT_PIN A2
+#define INT_PIN 3
+#define SW0_PIN 7
+#define SW1_PIN 6
+#define SW2_PIN 5
+#define SW3_PIN 4
+
+#define SLAVE_ADDRESS 0x09
+
+void i2c_send_handler(void);
+void button_handler(void);
+
+volatile uint8_t dip_sw = 0;
+volatile bool new_data = false;
+
+void setup()
+{
+ pinMode(MASTER_INT_PIN, OUTPUT);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ pinMode(INT_PIN, INPUT_PULLUP);
+ pinMode(SW0_PIN, INPUT_PULLUP);
+ pinMode(SW1_PIN, INPUT_PULLUP);
+ pinMode(SW2_PIN, INPUT_PULLUP);
+ pinMode(SW3_PIN, INPUT_PULLUP);
+
+ attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
+
+ Wire.begin(SLAVE_ADDRESS);
+ Wire.onRequest(i2c_send_handler);
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ uint8_t tmp = digitalRead(SW0_PIN) |
+ (digitalRead(SW1_PIN) << 1) |
+ (digitalRead(SW2_PIN) << 2) |
+ (digitalRead(SW3_PIN) << 3);
+ dip_sw = tmp;
+ if (new_data)
+ {
+ new_data = false;
+ digitalWrite(MASTER_INT_PIN, HIGH);
+ delayMicroseconds(5);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ delayMicroseconds(5);
+ }
+}
+
+void i2c_send_handler(void)
+{
+ Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
+}
+
+void button_handler(void)
+{
+ new_data = true;
+}
--- /dev/null
+#include <Wire.h>
+
+#define MASTER_INT_PIN A2
+#define INT_PIN 3
+#define SW0_PIN 7
+#define SW1_PIN 6
+#define SW2_PIN 5
+#define SW3_PIN 4
+
+#define SLAVE_ADDRESS 0x0A
+
+void i2c_send_handler(void);
+void button_handler(void);
+
+volatile uint8_t dip_sw = 0;
+volatile bool new_data = false;
+
+void setup()
+{
+ pinMode(MASTER_INT_PIN, OUTPUT);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ pinMode(INT_PIN, INPUT_PULLUP);
+ pinMode(SW0_PIN, INPUT_PULLUP);
+ pinMode(SW1_PIN, INPUT_PULLUP);
+ pinMode(SW2_PIN, INPUT_PULLUP);
+ pinMode(SW3_PIN, INPUT_PULLUP);
+
+ attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
+
+ Wire.begin(SLAVE_ADDRESS);
+ Wire.onRequest(i2c_send_handler);
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ uint8_t tmp = digitalRead(SW0_PIN) |
+ (digitalRead(SW1_PIN) << 1) |
+ (digitalRead(SW2_PIN) << 2) |
+ (digitalRead(SW3_PIN) << 3);
+ dip_sw = tmp;
+ if (new_data)
+ {
+ new_data = false;
+ digitalWrite(MASTER_INT_PIN, HIGH);
+ delayMicroseconds(5);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ delayMicroseconds(5);
+ }
+}
+
+void i2c_send_handler(void)
+{
+ Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
+}
+
+void button_handler(void)
+{
+ new_data = true;
+}
--- /dev/null
+https://www.tinkercad.com/things/78jf9y1YodC
--- /dev/null
+#include <Wire.h>
+
+#define INT_PIN 2
+
+#define SLAVE_ADDRESS 0x09
+
+size_t i2c_write(uint8_t address, void *data, size_t size);
+size_t i2c_read(uint8_t address, void *data, size_t size);
+void slave_interrupt(void);
+
+volatile bool new_data = false;
+
+void setup()
+{
+ Wire.begin();
+ Serial.begin(9600);
+ attachInterrupt(digitalPinToInterrupt(INT_PIN), slave_interrupt, RISING);
+}
+
+void loop()
+{
+ uint8_t dip_sw;
+
+ if (new_data)
+ {
+ i2c_read(SLAVE_ADDRESS, &dip_sw, sizeof(dip_sw));
+ Serial.println(dip_sw);
+ new_data = false;
+ }
+}
+
+size_t i2c_write(uint8_t address, void *data, size_t size)
+{
+ int error_code;
+ size_t bytes_written;
+
+ Wire.beginTransmission(address);
+ bytes_written = Wire.write((uint8_t *) data, size);
+ error_code = Wire.endTransmission();
+
+ return error_code ? 0: bytes_written;
+}
+
+size_t i2c_read(uint8_t address, void *data, size_t size)
+{
+ size_t bytes_received = Wire.requestFrom(address, size);
+
+ if (bytes_received == size)
+ {
+ for (size_t i = 0; i < size; i++)
+ {
+ ((uint8_t *) data)[i] = Wire.read();
+ }
+ }
+
+ return bytes_received;
+}
+
+void slave_interrupt(void)
+{
+ new_data = true;
+}
\ No newline at end of file
--- /dev/null
+#include <Wire.h>
+
+#define MASTER_INT_PIN A2
+#define INT_PIN 3
+#define SW0_PIN 7
+#define SW1_PIN 6
+#define SW2_PIN 5
+#define SW3_PIN 4
+
+#define SLAVE_ADDRESS 0x09
+
+void i2c_send_handler(void);
+void button_handler(void);
+
+volatile uint8_t dip_sw = 0;
+volatile bool new_data = false;
+
+void setup()
+{
+ pinMode(MASTER_INT_PIN, OUTPUT);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ pinMode(INT_PIN, INPUT_PULLUP);
+ pinMode(SW0_PIN, INPUT_PULLUP);
+ pinMode(SW1_PIN, INPUT_PULLUP);
+ pinMode(SW2_PIN, INPUT_PULLUP);
+ pinMode(SW3_PIN, INPUT_PULLUP);
+
+ attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
+
+ Wire.begin(SLAVE_ADDRESS);
+ Wire.onRequest(i2c_send_handler);
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ uint8_t tmp = digitalRead(SW0_PIN) |
+ (digitalRead(SW1_PIN) << 1) |
+ (digitalRead(SW2_PIN) << 2) |
+ (digitalRead(SW3_PIN) << 3);
+ dip_sw = tmp;
+ if (new_data)
+ {
+ new_data = false;
+ digitalWrite(MASTER_INT_PIN, HIGH);
+ delayMicroseconds(5);
+ digitalWrite(MASTER_INT_PIN, LOW);
+ delayMicroseconds(5);
+ }
+}
+
+void i2c_send_handler(void)
+{
+ Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
+}
+
+void button_handler(void)
+{
+ new_data = true;
+}
--- /dev/null
+https://www.tinkercad.com/things/bEpoUSShgaZ
--- /dev/null
+#include <Wire.h>
+
+#define SLAVE_ADDRESS 0x09
+#define DELAY_TIME 200
+
+size_t i2c_write(uint8_t address, void *data, size_t size);
+size_t i2c_read(uint8_t address, void *data, size_t size);
+
+void setup()
+{
+ Wire.begin();
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ static bool led_status = false;
+ uint16_t pot_value = 0;
+
+ Serial.print("Turning LED ");
+ Serial.println(led_status ? "on": "off");
+ i2c_write(SLAVE_ADDRESS, &led_status, sizeof(led_status));
+ led_status = !led_status;
+
+ i2c_read(SLAVE_ADDRESS, &pot_value, sizeof(pot_value));
+ Serial.print("Received pot_value = ");
+ Serial.println(pot_value);
+
+ delay(DELAY_TIME);
+}
+
+size_t i2c_write(uint8_t address, void *data, size_t size)
+{
+ int error_code;
+ size_t bytes_written;
+
+ Wire.beginTransmission(address);
+ bytes_written = Wire.write((uint8_t *) data, size);
+ error_code = Wire.endTransmission();
+
+ return error_code ? 0: bytes_written;
+}
+
+size_t i2c_read(uint8_t address, void *data, size_t size)
+{
+ size_t bytes_received = Wire.requestFrom(address, size);
+
+ if (bytes_received == size)
+ {
+ for (size_t i = 0; i < size; i++)
+ {
+ ((uint8_t *) data)[i] = Wire.read();
+ }
+ }
+
+ return bytes_received;
+}
--- /dev/null
+#include <Wire.h>
+
+#define POT_PIN A0
+#define LED_PIN 10
+
+#define SLAVE_ADDRESS 0x09
+
+void i2c_receive_handler(int bytes_received);
+void i2c_send_handler(void);
+
+volatile bool led_status = false;
+volatile uint16_t pot_value = 0;
+
+void setup()
+{
+ pinMode(POT_PIN, INPUT);
+ pinMode(LED_PIN, OUTPUT);
+ digitalWrite(LED_PIN, LOW);
+
+ Wire.begin(SLAVE_ADDRESS);
+ Wire.onRequest(i2c_send_handler);
+ Wire.onReceive(i2c_receive_handler);
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ digitalWrite(LED_PIN, led_status);
+ pot_value = analogRead(POT_PIN);
+}
+
+void i2c_send_handler(void)
+{
+ //Only for demonstration, never actually put Serial.print() in an ISR
+ Serial.print("Sending pot_value = ");
+ Serial.println(pot_value);
+ Wire.write((uint8_t *) &pot_value, sizeof(pot_value));
+}
+
+void i2c_receive_handler(int bytes_received)
+{
+ led_status = Wire.read();
+ // Ignore all bytes but the first
+ for (int i = 1; i < bytes_received; i++)
+ {
+ Wire.read();
+ }
+ //Only for demonstration, never actually put Serial.print() in an ISR
+ Serial.println(led_status ? "LED on": "LED off");
+}
--- /dev/null
+https://www.tinkercad.com/things/b5ZB55WFaxX
+++ /dev/null
-#include <Wire.h>
-
-#define INT_SLAVE1_PIN 3
-#define INT_SLAVE2_PIN 2
-
-#define SLAVE1_ADDRESS 0x09
-#define SLAVE2_ADDRESS 0x0A
-
-size_t i2c_write(uint8_t address, void *data, size_t size);
-size_t i2c_read(uint8_t address, void *data, size_t size);
-void slave1_interrupt(void);
-void slave2_interrupt(void);
-
-volatile bool new_data1 = false;
-volatile bool new_data2 = false;
-
-void setup()
-{
- Wire.begin();
- Serial.begin(9600);
- pinMode(INT_SLAVE1_PIN, INPUT);
- pinMode(INT_SLAVE2_PIN, INPUT);
- attachInterrupt(digitalPinToInterrupt(INT_SLAVE1_PIN), slave1_interrupt, RISING);
- attachInterrupt(digitalPinToInterrupt(INT_SLAVE2_PIN), slave2_interrupt, RISING);
-}
-
-void loop()
-{
- uint8_t dip_sw;
-
- if (new_data1)
- {
- i2c_read(SLAVE1_ADDRESS, &dip_sw, sizeof(dip_sw));
- Serial.print("From slave 1: ");
- Serial.println(dip_sw);
- new_data1 = false;
- }
- if (new_data2)
- {
- i2c_read(SLAVE2_ADDRESS, &dip_sw, sizeof(dip_sw));
- Serial.print("From slave 2: ");
- Serial.println(dip_sw);
- new_data2 = false;
- }
-}
-
-size_t i2c_write(uint8_t address, void *data, size_t size)
-{
- int error_code;
- size_t bytes_written;
-
- Wire.beginTransmission(address);
- bytes_written = Wire.write((uint8_t *) data, size);
- error_code = Wire.endTransmission();
-
- return error_code ? 0: bytes_written;
-}
-
-size_t i2c_read(uint8_t address, void *data, size_t size)
-{
- size_t bytes_received = Wire.requestFrom(address, size);
-
- if (bytes_received == size)
- {
- for (size_t i = 0; i < size; i++)
- {
- ((uint8_t *) data)[i] = Wire.read();
- }
- }
-
- return bytes_received;
-}
-
-void slave1_interrupt(void)
-{
- new_data1 = true;
-}
-
-void slave2_interrupt(void)
-{
- new_data2 = true;
-}
\ No newline at end of file
+++ /dev/null
-#include <Wire.h>
-
-#define MASTER_INT_PIN A2
-#define INT_PIN 3
-#define SW0_PIN 7
-#define SW1_PIN 6
-#define SW2_PIN 5
-#define SW3_PIN 4
-
-#define SLAVE_ADDRESS 0x09
-
-void i2c_send_handler(void);
-void button_handler(void);
-
-volatile uint8_t dip_sw = 0;
-volatile bool new_data = false;
-
-void setup()
-{
- pinMode(MASTER_INT_PIN, OUTPUT);
- digitalWrite(MASTER_INT_PIN, LOW);
- pinMode(INT_PIN, INPUT_PULLUP);
- pinMode(SW0_PIN, INPUT_PULLUP);
- pinMode(SW1_PIN, INPUT_PULLUP);
- pinMode(SW2_PIN, INPUT_PULLUP);
- pinMode(SW3_PIN, INPUT_PULLUP);
-
- attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
-
- Wire.begin(SLAVE_ADDRESS);
- Wire.onRequest(i2c_send_handler);
-
- Serial.begin(9600);
-}
-
-void loop()
-{
- uint8_t tmp = digitalRead(SW0_PIN) |
- (digitalRead(SW1_PIN) << 1) |
- (digitalRead(SW2_PIN) << 2) |
- (digitalRead(SW3_PIN) << 3);
- dip_sw = tmp;
- if (new_data)
- {
- new_data = false;
- digitalWrite(MASTER_INT_PIN, HIGH);
- delayMicroseconds(5);
- digitalWrite(MASTER_INT_PIN, LOW);
- delayMicroseconds(5);
- }
-}
-
-void i2c_send_handler(void)
-{
- Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
-}
-
-void button_handler(void)
-{
- new_data = true;
-}
+++ /dev/null
-#include <Wire.h>
-
-#define MASTER_INT_PIN A2
-#define INT_PIN 3
-#define SW0_PIN 7
-#define SW1_PIN 6
-#define SW2_PIN 5
-#define SW3_PIN 4
-
-#define SLAVE_ADDRESS 0x0A
-
-void i2c_send_handler(void);
-void button_handler(void);
-
-volatile uint8_t dip_sw = 0;
-volatile bool new_data = false;
-
-void setup()
-{
- pinMode(MASTER_INT_PIN, OUTPUT);
- digitalWrite(MASTER_INT_PIN, LOW);
- pinMode(INT_PIN, INPUT_PULLUP);
- pinMode(SW0_PIN, INPUT_PULLUP);
- pinMode(SW1_PIN, INPUT_PULLUP);
- pinMode(SW2_PIN, INPUT_PULLUP);
- pinMode(SW3_PIN, INPUT_PULLUP);
-
- attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
-
- Wire.begin(SLAVE_ADDRESS);
- Wire.onRequest(i2c_send_handler);
-
- Serial.begin(9600);
-}
-
-void loop()
-{
- uint8_t tmp = digitalRead(SW0_PIN) |
- (digitalRead(SW1_PIN) << 1) |
- (digitalRead(SW2_PIN) << 2) |
- (digitalRead(SW3_PIN) << 3);
- dip_sw = tmp;
- if (new_data)
- {
- new_data = false;
- digitalWrite(MASTER_INT_PIN, HIGH);
- delayMicroseconds(5);
- digitalWrite(MASTER_INT_PIN, LOW);
- delayMicroseconds(5);
- }
-}
-
-void i2c_send_handler(void)
-{
- Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
-}
-
-void button_handler(void)
-{
- new_data = true;
-}
+++ /dev/null
-https://www.tinkercad.com/things/78jf9y1YodC
+++ /dev/null
-#include <Wire.h>
-
-#define INT_PIN 2
-
-#define SLAVE_ADDRESS 0x09
-
-size_t i2c_write(uint8_t address, void *data, size_t size);
-size_t i2c_read(uint8_t address, void *data, size_t size);
-void slave_interrupt(void);
-
-volatile bool new_data = false;
-
-void setup()
-{
- Wire.begin();
- Serial.begin(9600);
- attachInterrupt(digitalPinToInterrupt(INT_PIN), slave_interrupt, RISING);
-}
-
-void loop()
-{
- uint8_t dip_sw;
-
- if (new_data)
- {
- i2c_read(SLAVE_ADDRESS, &dip_sw, sizeof(dip_sw));
- Serial.println(dip_sw);
- new_data = false;
- }
-}
-
-size_t i2c_write(uint8_t address, void *data, size_t size)
-{
- int error_code;
- size_t bytes_written;
-
- Wire.beginTransmission(address);
- bytes_written = Wire.write((uint8_t *) data, size);
- error_code = Wire.endTransmission();
-
- return error_code ? 0: bytes_written;
-}
-
-size_t i2c_read(uint8_t address, void *data, size_t size)
-{
- size_t bytes_received = Wire.requestFrom(address, size);
-
- if (bytes_received == size)
- {
- for (size_t i = 0; i < size; i++)
- {
- ((uint8_t *) data)[i] = Wire.read();
- }
- }
-
- return bytes_received;
-}
-
-void slave_interrupt(void)
-{
- new_data = true;
-}
\ No newline at end of file
+++ /dev/null
-#include <Wire.h>
-
-#define MASTER_INT_PIN A2
-#define INT_PIN 3
-#define SW0_PIN 7
-#define SW1_PIN 6
-#define SW2_PIN 5
-#define SW3_PIN 4
-
-#define SLAVE_ADDRESS 0x09
-
-void i2c_send_handler(void);
-void button_handler(void);
-
-volatile uint8_t dip_sw = 0;
-volatile bool new_data = false;
-
-void setup()
-{
- pinMode(MASTER_INT_PIN, OUTPUT);
- digitalWrite(MASTER_INT_PIN, LOW);
- pinMode(INT_PIN, INPUT_PULLUP);
- pinMode(SW0_PIN, INPUT_PULLUP);
- pinMode(SW1_PIN, INPUT_PULLUP);
- pinMode(SW2_PIN, INPUT_PULLUP);
- pinMode(SW3_PIN, INPUT_PULLUP);
-
- attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
-
- Wire.begin(SLAVE_ADDRESS);
- Wire.onRequest(i2c_send_handler);
-
- Serial.begin(9600);
-}
-
-void loop()
-{
- uint8_t tmp = digitalRead(SW0_PIN) |
- (digitalRead(SW1_PIN) << 1) |
- (digitalRead(SW2_PIN) << 2) |
- (digitalRead(SW3_PIN) << 3);
- dip_sw = tmp;
- if (new_data)
- {
- new_data = false;
- digitalWrite(MASTER_INT_PIN, HIGH);
- delayMicroseconds(5);
- digitalWrite(MASTER_INT_PIN, LOW);
- delayMicroseconds(5);
- }
-}
-
-void i2c_send_handler(void)
-{
- Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
-}
-
-void button_handler(void)
-{
- new_data = true;
-}
+++ /dev/null
-https://www.tinkercad.com/things/bEpoUSShgaZ
+++ /dev/null
-#include <Wire.h>
-
-#define SLAVE_ADDRESS 0x09
-#define DELAY_TIME 200
-
-size_t i2c_write(uint8_t address, void *data, size_t size);
-size_t i2c_read(uint8_t address, void *data, size_t size);
-
-void setup()
-{
- Wire.begin();
- Serial.begin(9600);
-}
-
-void loop()
-{
- static bool led_status = false;
- uint16_t pot_value = 0;
-
- Serial.print("Turning LED ");
- Serial.println(led_status ? "on": "off");
- i2c_write(SLAVE_ADDRESS, &led_status, sizeof(led_status));
- led_status = !led_status;
-
- i2c_read(SLAVE_ADDRESS, &pot_value, sizeof(pot_value));
- Serial.print("Received pot_value = ");
- Serial.println(pot_value);
-
- delay(DELAY_TIME);
-}
-
-size_t i2c_write(uint8_t address, void *data, size_t size)
-{
- int error_code;
- size_t bytes_written;
-
- Wire.beginTransmission(address);
- bytes_written = Wire.write((uint8_t *) data, size);
- error_code = Wire.endTransmission();
-
- return error_code ? 0: bytes_written;
-}
-
-size_t i2c_read(uint8_t address, void *data, size_t size)
-{
- size_t bytes_received = Wire.requestFrom(address, size);
-
- if (bytes_received == size)
- {
- for (size_t i = 0; i < size; i++)
- {
- ((uint8_t *) data)[i] = Wire.read();
- }
- }
-
- return bytes_received;
-}
+++ /dev/null
-#include <Wire.h>
-
-#define POT_PIN A0
-#define LED_PIN 10
-
-#define SLAVE_ADDRESS 0x09
-
-void i2c_receive_handler(int bytes_received);
-void i2c_send_handler(void);
-
-volatile bool led_status = false;
-volatile uint16_t pot_value = 0;
-
-void setup()
-{
- pinMode(POT_PIN, INPUT);
- pinMode(LED_PIN, OUTPUT);
- digitalWrite(LED_PIN, LOW);
-
- Wire.begin(SLAVE_ADDRESS);
- Wire.onRequest(i2c_send_handler);
- Wire.onReceive(i2c_receive_handler);
-
- Serial.begin(9600);
-}
-
-void loop()
-{
- digitalWrite(LED_PIN, led_status);
- pot_value = analogRead(POT_PIN);
-}
-
-void i2c_send_handler(void)
-{
- //Only for demonstration, never actually put Serial.print() in an ISR
- Serial.print("Sending pot_value = ");
- Serial.println(pot_value);
- Wire.write((uint8_t *) &pot_value, sizeof(pot_value));
-}
-
-void i2c_receive_handler(int bytes_received)
-{
- led_status = Wire.read();
- // Ignore all bytes but the first
- for (int i = 1; i < bytes_received; i++)
- {
- Wire.read();
- }
- //Only for demonstration, never actually put Serial.print() in an ISR
- Serial.println(led_status ? "LED on": "LED off");
-}
+++ /dev/null
-https://www.tinkercad.com/things/b5ZB55WFaxX
--- /dev/null
+#include <LiquidCrystal.h>
+
+#define UP_PIN 3
+#define DOWN_PIN 2
+
+#define RS_PIN 12
+#define EN_PIN 11
+#define D4_PIN 7
+#define D5_PIN 6
+#define D6_PIN 5
+#define D7_PIN 4
+
+#define COLUMNS 16
+#define ROWS 2
+
+void counter_up(void);
+void counter_down(void);
+
+LiquidCrystal lcd(RS_PIN, EN_PIN, D4_PIN, D5_PIN, D6_PIN, D7_PIN);
+volatile uint8_t counter = 0;
+
+void setup()
+{
+ delay(40); // LCD Power-On Reset (POR) initialization wait
+ lcd.begin(COLUMNS, ROWS);
+ pinMode(UP_PIN, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(UP_PIN), counter_up, FALLING);
+ pinMode(DOWN_PIN, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(DOWN_PIN), counter_down, FALLING);
+}
+
+void loop()
+{
+ lcd.setCursor(7, 0);
+ lcd.print(counter);
+}
+
+void counter_up(void)
+{
+ counter++;
+}
+
+void counter_down(void)
+{
+ counter--;
+}
--- /dev/null
+https://www.tinkercad.com/things/d6absXaO0GD
--- /dev/null
+#include <LiquidCrystal.h>
+
+#define RS 12
+#define EN 11
+#define D4 5
+#define D5 4
+#define D6 3
+#define D7 2
+
+#define COLS 16
+#define ROWS 2
+
+LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
+
+byte smiley[8] = {
+ B00000,
+ B10001,
+ B00000,
+ B00000,
+ B10001,
+ B01110,
+ B00000,
+};
+
+byte minecraft[] = {
+ B00000,
+ B00110,
+ B01000,
+ B10100,
+ B10010,
+ B00001,
+ B00000,
+ B00000
+};
+
+byte body[] = {
+ B00101,
+ B00110,
+ B11100,
+ B00100,
+ B00100,
+ B01010,
+ B10001,
+ B00000
+};
+
+void setup()
+{
+ delay(40); // LCD Power-On Reset (POR) initialization wait
+ lcd.createChar(0, smiley);
+ lcd.createChar(1, body);
+ lcd.createChar(2, minecraft);
+ lcd.begin(COLS, ROWS);
+ lcd.write(byte(0)); // Cast is needed for index 0 to prevent error
+ lcd.write(2);
+ lcd.setCursor(0, 1);
+ lcd.write(1);
+}
+
+void loop()
+{
+}
--- /dev/null
+ https://www.tinkercad.com/things/csH65U1Tvu4
\ No newline at end of file
--- /dev/null
+/*
+ LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight()
+
+ Demonstrates the use a 16x2 LCD display. The LiquidCrystal
+ library works with all LCD displays that are compatible with the
+ Hitachi HD44780 driver. There are many of them out there, and you
+ can usually tell them by the 16-pin interface.
+
+ This sketch prints "Hello World!" to the LCD and uses the
+ scrollDisplayLeft() and scrollDisplayRight() methods to scroll
+ the text.
+
+ The circuit:
+ * LCD RS pin to digital pin 12
+ * LCD Enable pin to digital pin 11
+ * LCD D4 pin to digital pin 5
+ * LCD D5 pin to digital pin 4
+ * LCD D6 pin to digital pin 3
+ * LCD D7 pin to digital pin 2
+ * LCD R/W pin to ground
+ * 10K resistor:
+ * ends to +5V and ground
+ * wiper to LCD VO pin (pin 3)
+
+ Library originally added 18 Apr 2008
+ by David A. Mellis
+ library modified 5 Jul 2009
+ by Limor Fried (http://www.ladyada.net)
+ example added 9 Jul 2009
+ by Tom Igoe
+ modified 22 Nov 2010
+ by Tom Igoe
+ modified 7 Nov 2016
+ by Arturo Guadalupi
+ modified 24 Feb 2021
+ by Vladimir Garistov
+
+ This example code is in the public domain.
+
+ http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll
+
+*/
+
+#include <LiquidCrystal.h>
+
+#define RS 12
+#define EN 11
+#define D4 5
+#define D5 4
+#define D6 3
+#define D7 2
+
+#define COLS 16
+#define ROWS 2
+
+// initialize the library by associating any needed LCD interface pin
+// with the arduino pin number it is connected to
+LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
+
+void setup()
+{
+ delay(40); // LCD Power-On Reset (POR) initialization wait
+ // set up the LCD's number of columns and rows:
+ lcd.begin(COLS, ROWS);
+ lcd.print("hello, world!");
+ delay(1000);
+}
+
+void loop()
+{
+ // scroll 13 positions (string length) to the left
+ // to move it offscreen left:
+ for (uint8_t positionCounter = 0; positionCounter < 13; positionCounter++)
+ {
+ // scroll one position left:
+ lcd.scrollDisplayLeft();
+ delay(150);
+ }
+
+ // scroll 29 positions (string length + display length) to the right
+ // to move it offscreen right:
+ for (uint8_t positionCounter = 0; positionCounter < 29; positionCounter++)
+ {
+ // scroll one position right:
+ lcd.scrollDisplayRight();
+ delay(150);
+ }
+
+ // scroll 16 positions (display length + string length) to the left
+ // to move it back to center:
+ for (uint8_t positionCounter = 0; positionCounter < 16; positionCounter++)
+ {
+ // scroll one position left:
+ lcd.scrollDisplayLeft();
+ delay(150);
+ }
+
+ delay(1000);
+}
--- /dev/null
+https://www.tinkercad.com/things/ecuRyTU9AaJ
--- /dev/null
+#include <LiquidCrystal.h>
+#include <string.h>
+
+#define SCROLL_DELAY 250
+#define LINE_DELAY 700
+
+#define RS 12
+#define EN 11
+#define D4 5
+#define D5 4
+#define D6 3
+#define D7 2
+
+#define COLS 16
+#define ROWS 2
+
+char *text[] =
+{
+ "LOREM IPSUM",
+ "qwertyuiop[",
+ "the quick brown fox jumped over the lazy dog"
+};
+
+LiquidCrystal LCD_screen(RS, EN, D4, D5, D6, D7);
+
+void setup()
+{
+ delay(40); // LCD Power-On Reset (POR) initialization wait
+ LCD_screen.begin(COLS, ROWS);
+ LCD_screen.clear();
+}
+
+void loop()
+{
+ uint8_t text_n;
+ int8_t position;
+ uint16_t i, j;
+ uint16_t l;
+ uint16_t print_size;
+
+ // Not necesarily the best implementation, feel free to submit a PR
+ for (text_n = 0; text_n < 3; text_n++)
+ {
+ l = strlen(text[text_n]);
+
+ for (position = COLS - 1; position >= 0; position--)
+ {
+ LCD_screen.setCursor(position, 0);
+ print_size = l;
+ if (print_size > COLS - position)
+ {
+ print_size = COLS - position;
+ }
+ for (i = 0; i < print_size; i++)
+ {
+ LCD_screen.write(text[text_n][i]);
+ }
+ delay(SCROLL_DELAY);
+ LCD_screen.clear();
+ }
+
+ for (j = 0; j < l; j++)
+ {
+ print_size = l - j;
+ if (print_size > COLS)
+ {
+ print_size = COLS;
+ }
+ for (i = 0; i < print_size; i++)
+ {
+ LCD_screen.write(text[text_n][j + i]);
+ }
+ delay(SCROLL_DELAY);
+ LCD_screen.clear();
+ }
+
+ delay(LINE_DELAY);
+ }
+}
--- /dev/null
+https://www.tinkercad.com/things/des9SoAMtAC
--- /dev/null
+#define RS 12
+#define EN 11
+#define D4 5
+#define D5 4
+#define D6 3
+#define D7 2
+
+#define COLS 16
+#define ROWS 2
+
+void lcd_cmd(uint8_t _data, bool _type);
+void lcd_init(void);
+void lcd_set_cursor(uint8_t col, uint8_t row);
+void lcd_show_char(char chr);
+void lcd_show_text(char *text, uint8_t len);
+void lcd_show_text_vmks(void);
+
+void setup() {
+ // Initialize LCD screen and IF GPIO
+ lcd_init();
+
+ // Center the text on the second line => Move cursor to
+ // (second line offset + half the line size - half the text size)
+ // (0x40 + 16/2 - 4/2) = (0x40 + 8 - 2) = (0x40 + 6) = 0x46
+ // Line 1 => 0x00 to 0x27
+ // Line 2 => 0x40 to 0x67
+ //lcd_cmd(B1100, 0); lcd_cmd(B0110, 0); // manually set DDRAM to cursor position = 0x46 = B 0100 0110
+ lcd_set_cursor(6, 2); // the same but using the function
+
+ // Show text
+ //lcd_show_text_vmks(); // Show hardcoded text "VMKS"
+ //lcd_show_char('T'); lcd_show_char('U'); lcd_show_char('E'); lcd_show_char('S');
+ lcd_show_text("VMKS", 4); // This is actually String object converting to char array but works for the demo
+}
+
+void loop() {
+ delay(5000);
+ lcd_cmd(B0000, 0); lcd_cmd(B0001, 0); delayMicroseconds(5*1530); // clear display - set all characters to space(' ') and return home
+ lcd_set_cursor(6, 1);
+ lcd_show_text_vmks();
+ lcd_set_cursor(6, 2);
+ lcd_show_char('T'); lcd_show_char('U'); lcd_show_char('E'); lcd_show_char('S');
+ while (1) {};
+}
+
+void lcd_init(void) {
+ // Set IF GPIO mode
+ pinMode(RS, OUTPUT);
+ pinMode(EN, OUTPUT);
+ pinMode(D4, OUTPUT);
+ pinMode(D5, OUTPUT);
+ pinMode(D6, OUTPUT);
+ pinMode(D7, OUTPUT);
+
+ // LCD Power-On Reset (POR) initialization wait
+ delay(40);
+
+ // Initialize controller HD44780
+ lcd_cmd(B0010, 0); delayMicroseconds(5*39); // Function set => 4-bit data bus mode, 1-line, 5x8 dots
+ lcd_cmd(B0010, 0); lcd_cmd(B1000, 0); delayMicroseconds(5*39); // Function set => 4-bit data bus mode, 2-line, 5x8 dots
+ lcd_cmd(B0000, 0); lcd_cmd(B0110, 0); delayMicroseconds(5*39); // entry mode set = left-justified, left-to-right, no shift text
+ lcd_cmd(B0000, 0); lcd_cmd(B0001, 0); delayMicroseconds(5*1530); // clear display - set all characters to space(' ') and return home
+ lcd_cmd(B0000, 0); lcd_cmd(B1100, 0); delayMicroseconds(5*39); // turn display on
+}
+
+// There is no parameter validation
+// COL and ROW start from 1
+void lcd_set_cursor(uint8_t col, uint8_t row) {
+ uint8_t row_offset[2] = {0x00, 0x40};
+ uint8_t pos = (col) + row_offset[row - 1];
+ pos = (pos & 0x7F) | 0x80; // Add cursor position change command code
+ uint8_t upper = (pos & 0xF0) >> 4;
+ uint8_t lower = (pos & 0x0F) >> 0;
+ lcd_cmd(upper, 0); lcd_cmd(lower, 0); delayMicroseconds(5*39); // set DDRAM address
+}
+
+// Send ASCII char
+void lcd_show_char(char chr) {
+ uint8_t upper = ((uint8_t)chr & 0xF0) >> 4;
+ uint8_t lower = ((uint8_t)chr & 0x0F) >> 0;
+
+ lcd_cmd(upper, 1); lcd_cmd(lower, 1); delayMicroseconds(5*43); // write data to DDRAM
+}
+
+// Send ASCII text
+void lcd_show_text(char *text, uint8_t len) {
+ for (uint8_t cnt = 0; cnt < len; cnt++) {
+ lcd_show_char(text[cnt]);
+ }
+}
+
+// Send hardcoded ASCII text "VMKS"
+void lcd_show_text_vmks(void) {
+ lcd_cmd(B0101, 1); lcd_cmd(B0110, 1); delayMicroseconds(5*43); // write data to DDRAM // V = 0x56 = B 0101 0110
+ lcd_cmd(B0100, 1); lcd_cmd(B1101, 1); delayMicroseconds(5*43); // write data to DDRAM // M = 0x4D = B 0100 1101
+ lcd_cmd(B0100, 1); lcd_cmd(B1011, 1); delayMicroseconds(5*43); // write data to DDRAM // K = 0x4B = B 0100 1011
+ lcd_cmd(B0101, 1); lcd_cmd(B0011, 1); delayMicroseconds(5*43); // write data to DDRAM // S = 0x53 = B 0101 0011
+}
+
+// Data = 4-bit data to send (use lower 4 bits)
+// Type 0 = Instruction || Type 1 = Data
+// Delay values are show just as example and are
+// minimum requiered values in [ns] multiplied by 2
+void lcd_cmd(uint8_t _data, bool _type) {
+ // Set RS
+ digitalWrite(RS, _type);
+
+ // Set Data value
+ digitalWrite(D4, (_data & 0x01));
+ digitalWrite(D5, (_data & 0x02));
+ digitalWrite(D6, (_data & 0x04));
+ digitalWrite(D7, (_data & 0x08));
+
+ // Time to select the register
+ delayMicroseconds(2*100); // tsu
+ // Data setup time = 60~90ns after the above delay
+ // In this example data is already set before that
+
+ // Pulse Enable
+ digitalWrite(EN, HIGH);
+ delayMicroseconds(2*300); // tw - Enable pulse duration
+ digitalWrite(EN, LOW);
+
+ // Wait
+ delayMicroseconds(2*10); // tc/th1/th2 - Data hold time
+}
--- /dev/null
+ https://www.tinkercad.com/things/9LSofZh54nf
\ No newline at end of file
--- /dev/null
+#define RS 12
+#define EN 11
+#define D4 5
+#define D5 4
+#define D6 3
+#define D7 2
+
+#define COLS 16
+#define ROWS 2
+
+void setup() {
+ // Initialize LCD screen and IF GPIO
+ lcd_init();
+
+ // Show hardcoded text "VMKS"
+ lcd_show_text_vmks();
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+}
+
+void lcd_init() {
+ // Set IF GPIO mode
+ pinMode(RS, OUTPUT);
+ pinMode(EN, OUTPUT);
+ pinMode(D4, OUTPUT);
+ pinMode(D5, OUTPUT);
+ pinMode(D6, OUTPUT);
+ pinMode(D7, OUTPUT);
+
+ // LCD Power-On Reset (POR) initialization wait
+ delay(40);
+
+ // Initialize controller HD44780
+ lcd_cmd(B0010, 0); delayMicroseconds(5*39); // Function set => 4-bit data bus mode, 1-line, 5x8 dots
+ lcd_cmd(B0010, 0); lcd_cmd(B1000, 0); delayMicroseconds(5*39); // Function set => 4-bit data bus mode, 2-line, 5x8 dots
+ lcd_cmd(B0000, 0); lcd_cmd(B0110, 0); delayMicroseconds(5*39); // entry mode set = left-justified, left-to-right, no shift text
+ lcd_cmd(B0000, 0); lcd_cmd(B0001, 0); delayMicroseconds(5*1530); // clear display - set all characters to space(' ') and return cursor to begining of first row (return home)
+ lcd_cmd(B0000, 0); lcd_cmd(B1100, 0); delayMicroseconds(5*39); // turn display on
+}
+
+// Send ASCII text "VMKS"
+void lcd_show_text_vmks() {
+ lcd_cmd(B0101, 1); lcd_cmd(B0110, 1); delayMicroseconds(5*43); // write data to DDRAM // V = 0x56 = B 0101 0110
+ lcd_cmd(B0100, 1); lcd_cmd(B1101, 1); delayMicroseconds(5*43); // write data to DDRAM // M = 0x4D = B 0100 1101
+ lcd_cmd(B0100, 1); lcd_cmd(B1011, 1); delayMicroseconds(5*43); // write data to DDRAM // K = 0x4B = B 0100 1011
+ lcd_cmd(B0101, 1); lcd_cmd(B0011, 1); delayMicroseconds(5*43); // write data to DDRAM // S = 0x53 = B 0101 0011
+}
+
+// Data = 4-bit data to send (use lower 4 bits)
+// Type 0 = Instruction || Type 1 = Data
+// Delay values are show just as example and are
+// minimum requiered values in [ns] multiplied by 2
+void lcd_cmd(uint8_t _data, bool _type) {
+ // Set RS
+ digitalWrite(RS, _type);
+
+ // Set Data value
+ digitalWrite(D4, (_data & 0x01));
+ digitalWrite(D5, (_data & 0x02));
+ digitalWrite(D6, (_data & 0x04));
+ digitalWrite(D7, (_data & 0x08));
+
+ // Time to select the register
+ delayMicroseconds(2*100); // tsu
+ // Data setup time = 60~90ns after the above delay
+ // In this example data is already set before that
+
+ // Pulse Enable
+ digitalWrite(EN, HIGH);
+ delayMicroseconds(2*300); // tw - Enable pulse duration
+ digitalWrite(EN, LOW);
+
+ // Wait
+ delayMicroseconds(2*10); // tc/th1/th2 - Data hold time
+}
--- /dev/null
+ https://www.tinkercad.com/things/enhJJzIeHyr
\ No newline at end of file
+++ /dev/null
-#include <LiquidCrystal.h>
-
-#define UP_PIN 3
-#define DOWN_PIN 2
-
-#define RS_PIN 12
-#define EN_PIN 11
-#define D4_PIN 7
-#define D5_PIN 6
-#define D6_PIN 5
-#define D7_PIN 4
-
-#define COLUMNS 16
-#define ROWS 2
-
-void counter_up(void);
-void counter_down(void);
-
-LiquidCrystal lcd(RS_PIN, EN_PIN, D4_PIN, D5_PIN, D6_PIN, D7_PIN);
-volatile uint8_t counter = 0;
-
-void setup()
-{
- delay(40); // LCD Power-On Reset (POR) initialization wait
- lcd.begin(COLUMNS, ROWS);
- pinMode(UP_PIN, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(UP_PIN), counter_up, FALLING);
- pinMode(DOWN_PIN, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(DOWN_PIN), counter_down, FALLING);
-}
-
-void loop()
-{
- lcd.setCursor(7, 0);
- lcd.print(counter);
-}
-
-void counter_up(void)
-{
- counter++;
-}
-
-void counter_down(void)
-{
- counter--;
-}
+++ /dev/null
-https://www.tinkercad.com/things/d6absXaO0GD
+++ /dev/null
-#include <LiquidCrystal.h>
-
-#define RS 12
-#define EN 11
-#define D4 5
-#define D5 4
-#define D6 3
-#define D7 2
-
-#define COLS 16
-#define ROWS 2
-
-LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
-
-byte smiley[8] = {
- B00000,
- B10001,
- B00000,
- B00000,
- B10001,
- B01110,
- B00000,
-};
-
-byte minecraft[] = {
- B00000,
- B00110,
- B01000,
- B10100,
- B10010,
- B00001,
- B00000,
- B00000
-};
-
-byte body[] = {
- B00101,
- B00110,
- B11100,
- B00100,
- B00100,
- B01010,
- B10001,
- B00000
-};
-
-void setup()
-{
- delay(40); // LCD Power-On Reset (POR) initialization wait
- lcd.createChar(0, smiley);
- lcd.createChar(1, body);
- lcd.createChar(2, minecraft);
- lcd.begin(COLS, ROWS);
- lcd.write(byte(0)); // Cast is needed for index 0 to prevent error
- lcd.write(2);
- lcd.setCursor(0, 1);
- lcd.write(1);
-}
-
-void loop()
-{
-}
+++ /dev/null
- https://www.tinkercad.com/things/csH65U1Tvu4
\ No newline at end of file
+++ /dev/null
-/*
- LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight()
-
- Demonstrates the use a 16x2 LCD display. The LiquidCrystal
- library works with all LCD displays that are compatible with the
- Hitachi HD44780 driver. There are many of them out there, and you
- can usually tell them by the 16-pin interface.
-
- This sketch prints "Hello World!" to the LCD and uses the
- scrollDisplayLeft() and scrollDisplayRight() methods to scroll
- the text.
-
- The circuit:
- * LCD RS pin to digital pin 12
- * LCD Enable pin to digital pin 11
- * LCD D4 pin to digital pin 5
- * LCD D5 pin to digital pin 4
- * LCD D6 pin to digital pin 3
- * LCD D7 pin to digital pin 2
- * LCD R/W pin to ground
- * 10K resistor:
- * ends to +5V and ground
- * wiper to LCD VO pin (pin 3)
-
- Library originally added 18 Apr 2008
- by David A. Mellis
- library modified 5 Jul 2009
- by Limor Fried (http://www.ladyada.net)
- example added 9 Jul 2009
- by Tom Igoe
- modified 22 Nov 2010
- by Tom Igoe
- modified 7 Nov 2016
- by Arturo Guadalupi
- modified 24 Feb 2021
- by Vladimir Garistov
-
- This example code is in the public domain.
-
- http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll
-
-*/
-
-#include <LiquidCrystal.h>
-
-#define RS 12
-#define EN 11
-#define D4 5
-#define D5 4
-#define D6 3
-#define D7 2
-
-#define COLS 16
-#define ROWS 2
-
-// initialize the library by associating any needed LCD interface pin
-// with the arduino pin number it is connected to
-LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
-
-void setup()
-{
- delay(40); // LCD Power-On Reset (POR) initialization wait
- // set up the LCD's number of columns and rows:
- lcd.begin(COLS, ROWS);
- lcd.print("hello, world!");
- delay(1000);
-}
-
-void loop()
-{
- // scroll 13 positions (string length) to the left
- // to move it offscreen left:
- for (uint8_t positionCounter = 0; positionCounter < 13; positionCounter++)
- {
- // scroll one position left:
- lcd.scrollDisplayLeft();
- delay(150);
- }
-
- // scroll 29 positions (string length + display length) to the right
- // to move it offscreen right:
- for (uint8_t positionCounter = 0; positionCounter < 29; positionCounter++)
- {
- // scroll one position right:
- lcd.scrollDisplayRight();
- delay(150);
- }
-
- // scroll 16 positions (display length + string length) to the left
- // to move it back to center:
- for (uint8_t positionCounter = 0; positionCounter < 16; positionCounter++)
- {
- // scroll one position left:
- lcd.scrollDisplayLeft();
- delay(150);
- }
-
- delay(1000);
-}
+++ /dev/null
-https://www.tinkercad.com/things/ecuRyTU9AaJ
+++ /dev/null
-#include <LiquidCrystal.h>
-#include <string.h>
-
-#define SCROLL_DELAY 250
-#define LINE_DELAY 700
-
-#define RS 12
-#define EN 11
-#define D4 5
-#define D5 4
-#define D6 3
-#define D7 2
-
-#define COLS 16
-#define ROWS 2
-
-char *text[] =
-{
- "LOREM IPSUM",
- "qwertyuiop[",
- "the quick brown fox jumped over the lazy dog"
-};
-
-LiquidCrystal LCD_screen(RS, EN, D4, D5, D6, D7);
-
-void setup()
-{
- delay(40); // LCD Power-On Reset (POR) initialization wait
- LCD_screen.begin(COLS, ROWS);
- LCD_screen.clear();
-}
-
-void loop()
-{
- uint8_t text_n;
- int8_t position;
- uint16_t i, j;
- uint16_t l;
- uint16_t print_size;
-
- // Not necesarily the best implementation, feel free to submit a PR
- for (text_n = 0; text_n < 3; text_n++)
- {
- l = strlen(text[text_n]);
-
- for (position = COLS - 1; position >= 0; position--)
- {
- LCD_screen.setCursor(position, 0);
- print_size = l;
- if (print_size > COLS - position)
- {
- print_size = COLS - position;
- }
- for (i = 0; i < print_size; i++)
- {
- LCD_screen.write(text[text_n][i]);
- }
- delay(SCROLL_DELAY);
- LCD_screen.clear();
- }
-
- for (j = 0; j < l; j++)
- {
- print_size = l - j;
- if (print_size > COLS)
- {
- print_size = COLS;
- }
- for (i = 0; i < print_size; i++)
- {
- LCD_screen.write(text[text_n][j + i]);
- }
- delay(SCROLL_DELAY);
- LCD_screen.clear();
- }
-
- delay(LINE_DELAY);
- }
-}
+++ /dev/null
-https://www.tinkercad.com/things/des9SoAMtAC
+++ /dev/null
-#define RS 12
-#define EN 11
-#define D4 5
-#define D5 4
-#define D6 3
-#define D7 2
-
-#define COLS 16
-#define ROWS 2
-
-void lcd_cmd(uint8_t _data, bool _type);
-void lcd_init(void);
-void lcd_set_cursor(uint8_t col, uint8_t row);
-void lcd_show_char(char chr);
-void lcd_show_text(char *text, uint8_t len);
-void lcd_show_text_vmks(void);
-
-void setup() {
- // Initialize LCD screen and IF GPIO
- lcd_init();
-
- // Center the text on the second line => Move cursor to
- // (second line offset + half the line size - half the text size)
- // (0x40 + 16/2 - 4/2) = (0x40 + 8 - 2) = (0x40 + 6) = 0x46
- // Line 1 => 0x00 to 0x27
- // Line 2 => 0x40 to 0x67
- //lcd_cmd(B1100, 0); lcd_cmd(B0110, 0); // manually set DDRAM to cursor position = 0x46 = B 0100 0110
- lcd_set_cursor(6, 2); // the same but using the function
-
- // Show text
- //lcd_show_text_vmks(); // Show hardcoded text "VMKS"
- //lcd_show_char('T'); lcd_show_char('U'); lcd_show_char('E'); lcd_show_char('S');
- lcd_show_text("VMKS", 4); // This is actually String object converting to char array but works for the demo
-}
-
-void loop() {
- delay(5000);
- lcd_cmd(B0000, 0); lcd_cmd(B0001, 0); delayMicroseconds(5*1530); // clear display - set all characters to space(' ') and return home
- lcd_set_cursor(6, 1);
- lcd_show_text_vmks();
- lcd_set_cursor(6, 2);
- lcd_show_char('T'); lcd_show_char('U'); lcd_show_char('E'); lcd_show_char('S');
- while (1) {};
-}
-
-void lcd_init(void) {
- // Set IF GPIO mode
- pinMode(RS, OUTPUT);
- pinMode(EN, OUTPUT);
- pinMode(D4, OUTPUT);
- pinMode(D5, OUTPUT);
- pinMode(D6, OUTPUT);
- pinMode(D7, OUTPUT);
-
- // LCD Power-On Reset (POR) initialization wait
- delay(40);
-
- // Initialize controller HD44780
- lcd_cmd(B0010, 0); delayMicroseconds(5*39); // Function set => 4-bit data bus mode, 1-line, 5x8 dots
- lcd_cmd(B0010, 0); lcd_cmd(B1000, 0); delayMicroseconds(5*39); // Function set => 4-bit data bus mode, 2-line, 5x8 dots
- lcd_cmd(B0000, 0); lcd_cmd(B0110, 0); delayMicroseconds(5*39); // entry mode set = left-justified, left-to-right, no shift text
- lcd_cmd(B0000, 0); lcd_cmd(B0001, 0); delayMicroseconds(5*1530); // clear display - set all characters to space(' ') and return home
- lcd_cmd(B0000, 0); lcd_cmd(B1100, 0); delayMicroseconds(5*39); // turn display on
-}
-
-// There is no parameter validation
-// COL and ROW start from 1
-void lcd_set_cursor(uint8_t col, uint8_t row) {
- uint8_t row_offset[2] = {0x00, 0x40};
- uint8_t pos = (col) + row_offset[row - 1];
- pos = (pos & 0x7F) | 0x80; // Add cursor position change command code
- uint8_t upper = (pos & 0xF0) >> 4;
- uint8_t lower = (pos & 0x0F) >> 0;
- lcd_cmd(upper, 0); lcd_cmd(lower, 0); delayMicroseconds(5*39); // set DDRAM address
-}
-
-// Send ASCII char
-void lcd_show_char(char chr) {
- uint8_t upper = ((uint8_t)chr & 0xF0) >> 4;
- uint8_t lower = ((uint8_t)chr & 0x0F) >> 0;
-
- lcd_cmd(upper, 1); lcd_cmd(lower, 1); delayMicroseconds(5*43); // write data to DDRAM
-}
-
-// Send ASCII text
-void lcd_show_text(char *text, uint8_t len) {
- for (uint8_t cnt = 0; cnt < len; cnt++) {
- lcd_show_char(text[cnt]);
- }
-}
-
-// Send hardcoded ASCII text "VMKS"
-void lcd_show_text_vmks(void) {
- lcd_cmd(B0101, 1); lcd_cmd(B0110, 1); delayMicroseconds(5*43); // write data to DDRAM // V = 0x56 = B 0101 0110
- lcd_cmd(B0100, 1); lcd_cmd(B1101, 1); delayMicroseconds(5*43); // write data to DDRAM // M = 0x4D = B 0100 1101
- lcd_cmd(B0100, 1); lcd_cmd(B1011, 1); delayMicroseconds(5*43); // write data to DDRAM // K = 0x4B = B 0100 1011
- lcd_cmd(B0101, 1); lcd_cmd(B0011, 1); delayMicroseconds(5*43); // write data to DDRAM // S = 0x53 = B 0101 0011
-}
-
-// Data = 4-bit data to send (use lower 4 bits)
-// Type 0 = Instruction || Type 1 = Data
-// Delay values are show just as example and are
-// minimum requiered values in [ns] multiplied by 2
-void lcd_cmd(uint8_t _data, bool _type) {
- // Set RS
- digitalWrite(RS, _type);
-
- // Set Data value
- digitalWrite(D4, (_data & 0x01));
- digitalWrite(D5, (_data & 0x02));
- digitalWrite(D6, (_data & 0x04));
- digitalWrite(D7, (_data & 0x08));
-
- // Time to select the register
- delayMicroseconds(2*100); // tsu
- // Data setup time = 60~90ns after the above delay
- // In this example data is already set before that
-
- // Pulse Enable
- digitalWrite(EN, HIGH);
- delayMicroseconds(2*300); // tw - Enable pulse duration
- digitalWrite(EN, LOW);
-
- // Wait
- delayMicroseconds(2*10); // tc/th1/th2 - Data hold time
-}
+++ /dev/null
- https://www.tinkercad.com/things/9LSofZh54nf
\ No newline at end of file
+++ /dev/null
-#define RS 12
-#define EN 11
-#define D4 5
-#define D5 4
-#define D6 3
-#define D7 2
-
-#define COLS 16
-#define ROWS 2
-
-void setup() {
- // Initialize LCD screen and IF GPIO
- lcd_init();
-
- // Show hardcoded text "VMKS"
- lcd_show_text_vmks();
-}
-
-void loop() {
- // put your main code here, to run repeatedly:
-}
-
-void lcd_init() {
- // Set IF GPIO mode
- pinMode(RS, OUTPUT);
- pinMode(EN, OUTPUT);
- pinMode(D4, OUTPUT);
- pinMode(D5, OUTPUT);
- pinMode(D6, OUTPUT);
- pinMode(D7, OUTPUT);
-
- // LCD Power-On Reset (POR) initialization wait
- delay(40);
-
- // Initialize controller HD44780
- lcd_cmd(B0010, 0); delayMicroseconds(5*39); // Function set => 4-bit data bus mode, 1-line, 5x8 dots
- lcd_cmd(B0010, 0); lcd_cmd(B1000, 0); delayMicroseconds(5*39); // Function set => 4-bit data bus mode, 2-line, 5x8 dots
- lcd_cmd(B0000, 0); lcd_cmd(B0110, 0); delayMicroseconds(5*39); // entry mode set = left-justified, left-to-right, no shift text
- lcd_cmd(B0000, 0); lcd_cmd(B0001, 0); delayMicroseconds(5*1530); // clear display - set all characters to space(' ') and return cursor to begining of first row (return home)
- lcd_cmd(B0000, 0); lcd_cmd(B1100, 0); delayMicroseconds(5*39); // turn display on
-}
-
-// Send ASCII text "VMKS"
-void lcd_show_text_vmks() {
- lcd_cmd(B0101, 1); lcd_cmd(B0110, 1); delayMicroseconds(5*43); // write data to DDRAM // V = 0x56 = B 0101 0110
- lcd_cmd(B0100, 1); lcd_cmd(B1101, 1); delayMicroseconds(5*43); // write data to DDRAM // M = 0x4D = B 0100 1101
- lcd_cmd(B0100, 1); lcd_cmd(B1011, 1); delayMicroseconds(5*43); // write data to DDRAM // K = 0x4B = B 0100 1011
- lcd_cmd(B0101, 1); lcd_cmd(B0011, 1); delayMicroseconds(5*43); // write data to DDRAM // S = 0x53 = B 0101 0011
-}
-
-// Data = 4-bit data to send (use lower 4 bits)
-// Type 0 = Instruction || Type 1 = Data
-// Delay values are show just as example and are
-// minimum requiered values in [ns] multiplied by 2
-void lcd_cmd(uint8_t _data, bool _type) {
- // Set RS
- digitalWrite(RS, _type);
-
- // Set Data value
- digitalWrite(D4, (_data & 0x01));
- digitalWrite(D5, (_data & 0x02));
- digitalWrite(D6, (_data & 0x04));
- digitalWrite(D7, (_data & 0x08));
-
- // Time to select the register
- delayMicroseconds(2*100); // tsu
- // Data setup time = 60~90ns after the above delay
- // In this example data is already set before that
-
- // Pulse Enable
- digitalWrite(EN, HIGH);
- delayMicroseconds(2*300); // tw - Enable pulse duration
- digitalWrite(EN, LOW);
-
- // Wait
- delayMicroseconds(2*10); // tc/th1/th2 - Data hold time
-}
+++ /dev/null
- https://www.tinkercad.com/things/enhJJzIeHyr
\ No newline at end of file
+++ /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
+#include <Adafruit_NeoPixel.h>
+#include <inttypes.h>
+
+#define ROWS 8
+#define COLS 32
+#define NUM_PIXELS (ROWS * COLS)
+#define PPM_HEADER_LENGHT 12
+#define BIG_IMAGE_FILE_SIZE 780
+#define DIMM 4
+
+#define Y_U_NO_WORK
+//#define STM32
+
+#ifdef STM32
+#define LED_PIN PA2
+#else
+#define LED_PIN 12
+#endif
+
+int render_image(uint8_t buff[ROWS][COLS][3], const uint8_t image[]);
+int display_rgb(uint8_t buff[ROWS][COLS][3]);
+int display_rgb_direct(const uint8_t image[]);
+
+static const uint8_t big_image_data[BIG_IMAGE_FILE_SIZE] =
+{
+ 0x50, 0x36, 0x0a, 0x33, 0x32, 0x20, 0x38, 0x0a, 0x32, 0x35, 0x35, 0x0a,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00,
+ 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00,
+ 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+Adafruit_NeoPixel led_matrix(NUM_PIXELS, LED_PIN, NEO_GRB);
+
+void setup()
+{
+ led_matrix.begin();
+ led_matrix.fill(led_matrix.Color(0, 20 / DIMM, 6 / DIMM));
+}
+
+void loop()
+{
+ #ifdef Y_U_NO_WORK
+
+ volatile uint8_t hax[27] = {0}; // Interesting values: 19, 20-31, 32, 50
+ uint8_t frame_buffer[ROWS][COLS][3] = {{{0}}};
+
+ render_image(frame_buffer, big_image_data);
+ display_rgb(frame_buffer);
+
+ #else
+
+ display_rgb_direct(big_image_data);
+
+ #endif
+}
+
+int render_image(uint8_t buff[ROWS][COLS][3], const uint8_t image[])
+{
+ size_t row_offset, col_offset;
+
+ if (buff == NULL || image == NULL)
+ return -1;
+
+ for (uint8_t row = 0; row < ROWS; row++)
+ {
+ row_offset = row * COLS * 3;
+ for (uint8_t col = 0; col < COLS; col++)
+ {
+ col_offset = col * 3;
+ for (uint8_t i = 0; i < 3; i++)
+ {
+ buff[row][col][i] = image[PPM_HEADER_LENGHT + row_offset + col_offset + i];
+ }
+ }
+ }
+
+ return 0;
+}
+
+int display_rgb(uint8_t buff[ROWS][COLS][3])
+{
+ if (buff == NULL)
+ return -1;
+
+ for (uint8_t col = 0; col < COLS; col += 2)
+ {
+ for (uint8_t row = 0; row < ROWS; row++)
+ {
+ if (buff[row][col][0] || buff[row][col][1] || buff[row][col][2])
+ {
+ led_matrix.setPixelColor(col * ROWS + row,
+ led_matrix.Color(buff[row][col][0] / DIMM,
+ buff[row][col][1] / DIMM,
+ buff[row][col][2] / DIMM));
+ }
+ }
+ }
+ for (uint8_t col = 1; col < COLS; col += 2)
+ {
+ for (uint8_t row = 0; row < ROWS; row++)
+ {
+ if (buff[row][col][0] || buff[row][col][1] || buff[row][col][2])
+ {
+ led_matrix.setPixelColor((col + 1) * ROWS - row - 1,
+ led_matrix.Color(buff[row][col][0] / DIMM,
+ buff[row][col][1] / DIMM,
+ buff[row][col][2] / DIMM));
+ }
+ }
+ }
+ led_matrix.show();
+
+ return 0;
+}
+
+int display_rgb_direct(const uint8_t image[])
+{
+ size_t row_offset, col_offset, offset;
+
+ if (image == NULL)
+ return -1;
+
+ for (uint8_t col = 0; col < COLS; col += 2)
+ {
+ col_offset = col * 3;
+ for (uint8_t row = 0; row < ROWS; row++)
+ {
+ row_offset = row * COLS * 3;
+ offset = PPM_HEADER_LENGHT + row_offset + col_offset;
+ if (image[offset] || image[offset + 1] || image[offset + 2])
+ {
+ led_matrix.setPixelColor(col * ROWS + row,
+ led_matrix.Color(image[offset] / DIMM,
+ image[offset + 1] / DIMM,
+ image[offset + 2] / DIMM));
+ }
+ }
+ }
+ for (uint8_t col = 1; col < COLS; col += 2)
+ {
+ col_offset = col * 3;
+ for (uint8_t row = 0; row < ROWS; row++)
+ {
+ row_offset = row * COLS * 3;
+ offset = PPM_HEADER_LENGHT + row_offset + col_offset;
+ if (image[offset] || image[offset + 1] || image[offset + 2])
+ {
+ led_matrix.setPixelColor((col + 1) * ROWS - row - 1,
+ led_matrix.Color(image[offset] / DIMM,
+ image[offset + 1] / DIMM,
+ image[offset + 2] / DIMM));
+ }
+ }
+ }
+ led_matrix.show();
+
+ return 0;
+}
--- /dev/null
+https://www.tinkercad.com/things/eOSmRi4TA7z-bigledstrip
--- /dev/null
+#include <Adafruit_NeoPixel.h>
+
+#define NUM_PIXELS 6
+#define MIN_DELAY 30
+
+#define TOP_ROW 2
+#define MID_ROW 3
+#define BOT_ROW 4
+#define UP_BUTTON 6
+#define DOWN_BUTTON 5
+#define NOISE A0
+
+#define PLAYER 1
+#define CAR 2
+#define EMPTY 0
+#define CRASH 3
+
+Adafruit_NeoPixel top_row(NUM_PIXELS, TOP_ROW, NEO_GRB);
+Adafruit_NeoPixel mid_row(NUM_PIXELS, MID_ROW, NEO_GRB);
+Adafruit_NeoPixel bot_row(NUM_PIXELS, BOT_ROW, NEO_GRB);
+
+// Video RAM - every element corresponds to one pixel
+int vram[3][NUM_PIXELS] = {{0}}; // 2 - TOP, 1 - MID, 0 - BOT
+int player_pos = 1;
+int next_car_in = 1;
+int delay_time = 500;
+int crashed = 0;
+
+void setup()
+{
+ pinMode(TOP_ROW, OUTPUT);
+ pinMode(MID_ROW, OUTPUT);
+ pinMode(BOT_ROW, OUTPUT);
+ pinMode(UP_BUTTON, INPUT);
+ pinMode(DOWN_BUTTON, INPUT);
+ pinMode(NOISE, INPUT);
+
+ // LED strip initialization
+ top_row.begin();
+ mid_row.begin();
+ bot_row.begin();
+
+ // set the seed for the random number generator
+ int seed = analogRead(NOISE) * 42;
+ randomSeed(seed);
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ int i;
+ int new_car;
+
+ // update player position
+ if (digitalRead(UP_BUTTON) == HIGH)
+ {
+ player_pos++;
+ }
+ else if (digitalRead(DOWN_BUTTON) == HIGH)
+ {
+ player_pos--;
+ }
+ if (player_pos > 2)
+ {
+ player_pos = 2;
+ }
+ else if (player_pos < 0)
+ {
+ player_pos = 0;
+ }
+
+ // draw the player
+ for (i = 0; i < 3; i++)
+ {
+ if (player_pos == i)
+ {
+ // detect collision
+ if (vram[i][1] == CAR)
+ {
+ vram[i][0] = CRASH;
+ crashed = 1;
+ }
+ else
+ {
+ vram[i][0] = PLAYER;
+ }
+ }
+ else
+ {
+ vram[i][0] = vram[i][1];
+ }
+ }
+
+ // move everything one pixel to the left
+ for (i = 1; i < (NUM_PIXELS - 1); i++)
+ {
+ vram[0][i] = vram[0][i + 1];
+ vram[1][i] = vram[1][i + 1];
+ vram[2][i] = vram[2][i + 1];
+ }
+
+ // generate next car
+ for (i = 0; i < 3; i++)
+ {
+ vram[i][NUM_PIXELS - 1] = EMPTY;
+ }
+ next_car_in--;
+ if (next_car_in == 0)
+ {
+ new_car = random(3);
+ vram[new_car][NUM_PIXELS - 1] = CAR;
+ next_car_in = 3;
+ }
+
+ // render the image
+ // Note: this was originally made for a couple of younger kids who hadn't learned about switch-case yet
+ for (i = 0; i < NUM_PIXELS; i++)
+ {
+ if (vram[0][i] == EMPTY)
+ {
+ bot_row.setPixelColor(i, bot_row.Color(0, 0, 0));
+ }
+ else if (vram[0][i] == CAR)
+ {
+ bot_row.setPixelColor(i, bot_row.Color(0, 0, 255));
+ }
+ else if (vram[0][i] == PLAYER)
+ {
+ bot_row.setPixelColor(i, bot_row.Color(0, 255, 0));
+ }
+ else if (vram[0][i] == CRASH)
+ {
+ bot_row.setPixelColor(i, bot_row.Color(255, 0, 0));
+ }
+
+ if (vram[1][i] == EMPTY)
+ {
+ mid_row.setPixelColor(i, mid_row.Color(0, 0, 0));
+ }
+ else if (vram[1][i] == CAR)
+ {
+ mid_row.setPixelColor(i, mid_row.Color(0, 0, 255));
+ }
+ else if (vram[1][i] == PLAYER)
+ {
+ mid_row.setPixelColor(i, mid_row.Color(0, 255, 0));
+ }
+ else if (vram[1][i] == CRASH)
+ {
+ mid_row.setPixelColor(i, mid_row.Color(255, 0, 0));
+ }
+
+ if (vram[2][i] == EMPTY)
+ {
+ top_row.setPixelColor(i, top_row.Color(0, 0, 0));
+ }
+ else if (vram[2][i] == CAR)
+ {
+ top_row.setPixelColor(i, top_row.Color(0, 0, 255));
+ }
+ else if (vram[2][i] == PLAYER)
+ {
+ top_row.setPixelColor(i, top_row.Color(0, 255, 0));
+ }
+ else if (vram[2][i] == CRASH)
+ {
+ top_row.setPixelColor(i, top_row.Color(255, 0, 0));
+ }
+ }
+ top_row.show();
+ mid_row.show();
+ bot_row.show();
+ Serial.println(delay_time);
+ // stop the game if crashed
+ if (crashed)
+ {
+ while (1);
+ }
+ // delay before the next frame
+ else
+ {
+ delay(delay_time);
+ }
+ // slowly make the game faster
+ if (delay_time > MIN_DELAY)
+ {
+ delay_time--;
+ }
+}
--- /dev/null
+https://www.tinkercad.com/things/0J1F6FpWf9y
--- /dev/null
+// Generate an LED gamma-correction table for Arduino sketches.
+// Copy-and-paste the program's output into an Arduino sketch.
+
+float gamma = 2.2; // Correction factor
+uint8_t max_in = 255; // Top end of INPUT range
+uint8_t max_out = 255; // Top end of OUTPUT range
+
+uint8_t temp = 0;
+
+void setup() {
+ Serial.begin(9600);
+ Serial.print("const uint8_t PROGMEM gamma[] = {");
+ for (int i = 0; i <= max_in; i++) {
+ if (i > 0) Serial.print(',');
+ if ((i & 15) == 0) Serial.print("\n ");
+ temp = (uint8_t)(pow((float)i / (float)max_in, gamma) * max_out + 0.5);
+ Serial.print(temp);
+ }
+ Serial.println("\n };");
+}
+
+void loop() {
+
+}
--- /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
+#define LED 9
+uint32_t br = 0;
+void setup() {
+ pinMode(LED, OUTPUT);
+}
+void loop() {
+ for (uint32_t x = 0; x < 100; x++) {
+ //br = (x*250)/100; // Gamma - NO
+ //br = (x*x)/40; // Gamma - 2
+ br = (x*x*x)/4000; // Gamma - 3
+ analogWrite(LED,br);
+ delay(20);
+ }
+ for (uint32_t x = 100; x > 0; x--) {
+ //br = (x*250)/100; // Gamma - NO
+ //br = (x*x)/40; // Gamma - 2
+ br = (x*x*x)/4000; // Gamma - 3
+ analogWrite(LED,br);
+ delay(20);
+ }
+}
--- /dev/null
+#include <Adafruit_NeoPixel.h>
+#define LED_PIN 6
+#define LED_ROW 8
+#define LED_COL 8
+#define LED_COUNT (LED_ROW * LED_COL)
+
+Adafruit_NeoPixel matrix(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
+
+uint32_t brightness = 0;
+
+void setup() {
+ matrix.begin();
+ matrix.show();
+ matrix.setBrightness(255);
+}
+
+void loop() {
+ for (uint32_t x = 0; x < 100; x++) {
+ //brightness = (x*250)/100; // Gamma - NO
+ //brightness = (x*x)/40; // Gamma - 2
+ brightness = (x*x*x)/4000; // Gamma - 3
+ matrix.setPixelColor(0, (uint8_t)brightness, 0, 0);
+ matrix.show();
+ delay(20);
+ }
+ for (uint32_t x = 100; x > 0; x--) {
+ //brightness = (x*250)/100; // Gamma - NO
+ //brightness = (x*x)/40; // Gamma - 2
+ brightness = (x*x*x)/4000; // Gamma - 3
+ matrix.setPixelColor(0, (uint8_t)brightness, 0, 0);
+ matrix.show();
+ delay(20);
+ }
+}
--- /dev/null
+#include <Adafruit_NeoPixel.h>
+#define LED_PIN 6
+#define LED_ROW 8
+#define LED_COL 8
+#define LED_COUNT (LED_ROW * LED_COL)
+
+Adafruit_NeoPixel matrix(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
+
+uint32_t brightness = 0;
+
+// This way the LUT can be at the bottom of the code
+extern const uint8_t gamma[];
+
+// L - emitted light by the LED
+// B - perceived brightness by the EYE
+
+// Single color
+// B=L^(1/gamma)
+// L=B^(gamma)
+
+// RGB MultiColor
+// B=(Red^gamma+Green^gamma+Blue^gamma)^(1/gamma)
+
+void setup() {
+ matrix.begin();
+ matrix.show();
+ matrix.setBrightness(255);
+}
+
+void loop() {
+ for (uint8_t x = 0; x < 100; x++) {
+ setRGB(0, 100, x, 0);
+ matrix.show();
+ delay(20);
+ }
+ for (uint8_t x = 100; x > 0; x--) {
+ setRGB(0, x, 100, 0);
+ matrix.show();
+ delay(20);
+ }
+ for (uint8_t x = 0; x < 100; x++) {
+ setRGB(0, x, 100, 0);
+ matrix.show();
+ delay(20);
+ }
+ for (uint8_t x = 100; x > 0; x--) {
+ setRGB(0, 100, x, 0);
+ matrix.show();
+ delay(20);
+ }
+}
+
+void setRGB(uint8_t pixelNumber, uint8_t red, uint8_t green, uint8_t blue) {
+ matrix.setPixelColor(pixelNumber,
+ pgm_read_byte(&gamma[red]),
+ pgm_read_byte(&gamma[green]),
+ pgm_read_byte(&gamma[blue]));
+}
+
+// Gamma 2.2
+
+const uint8_t PROGMEM gamma[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
+ 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6,
+ 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12,
+ 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19,
+ 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, 29,
+ 30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41,
+ 42, 43, 43, 44, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55,
+ 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
+ 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 87, 88, 89, 90,
+ 91, 93, 94, 95, 97, 98, 99, 100, 102, 103, 105, 106, 107, 109, 110, 111,
+ 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135,
+ 137, 138, 140, 141, 143, 145, 146, 148, 149, 151, 153, 154, 156, 158, 159, 161,
+ 163, 165, 166, 168, 170, 172, 173, 175, 177, 179, 181, 182, 184, 186, 188, 190,
+ 192, 194, 196, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221,
+ 223, 225, 227, 229, 231, 234, 236, 238, 240, 242, 244, 246, 248, 251, 253, 255
+};
+
+
+// Gamma 1.8
+/*
+ const uint8_t PROGMEM gamma[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2,
+ 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6,
+ 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12,
+ 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 21,
+ 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31,
+ 32, 32, 33, 34, 35, 35, 36, 37, 38, 38, 39, 40, 41, 41, 42, 43,
+ 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
+ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90,
+ 91, 92, 93, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 107, 108, 109,
+ 110, 111, 113, 114, 115, 116, 118, 119, 120, 122, 123, 124, 126, 127, 128, 129,
+ 131, 132, 134, 135, 136, 138, 139, 140, 142, 143, 145, 146, 147, 149, 150, 152,
+ 153, 154, 156, 157, 159, 160, 162, 163, 165, 166, 168, 169, 171, 172, 174, 175,
+ 177, 178, 180, 181, 183, 184, 186, 188, 189, 191, 192, 194, 195, 197, 199, 200,
+ 202, 204, 205, 207, 208, 210, 212, 213, 215, 217, 218, 220, 222, 224, 225, 227,
+ 229, 230, 232, 234, 236, 237, 239, 241, 243, 244, 246, 248, 250, 251, 253, 255
+ };
+*/
+
+// Gamma 2.8
+/*
+ const uint8_t PROGMEM gamma[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
+ 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
+ 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
+ 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
+ 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
+ 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
+ 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
+ 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
+ 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
+ 90, 92, 93, 95, 96, 98, 99, 101, 102, 104, 105, 107, 109, 110, 112, 114,
+ 115, 117, 119, 120, 122, 124, 126, 127, 129, 131, 133, 135, 137, 138, 140, 142,
+ 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 167, 169, 171, 173, 175,
+ 177, 180, 182, 184, 186, 189, 191, 193, 196, 198, 200, 203, 205, 208, 210, 213,
+ 215, 218, 220, 223, 225, 228, 231, 233, 236, 239, 241, 244, 247, 249, 252, 255
+ };
+*/
--- /dev/null
+#include <Adafruit_NeoPixel.h>
+#include <inttypes.h>
+
+#define NUM_PIXELS 16
+
+#define TOP_ROW 4
+#define MID_ROW 3
+#define BOT_ROW 2
+
+#define PPM_HEADER_LENGHT 58
+#define IMAGE_FILE_LENGHT 202
+
+/*
+typedef enum {RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN} simple_color_t;
+int display_enum(simple_color_t buff[]);
+*/
+
+int render_image(uint8_t buff[3][NUM_PIXELS][3], const uint8_t image[]);
+int display_rgb(uint8_t buff[3][NUM_PIXELS][3]);
+
+const uint8_t image_data_0[IMAGE_FILE_LENGHT] =
+{
+ 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
+ 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31,
+ 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e,
+ 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0x78, 0x90, 0xbc, 0x7b, 0x93,
+ 0xbe, 0x7e, 0x98, 0xbe, 0x7e, 0x98, 0xbc, 0x7d, 0x98, 0xba, 0x7b, 0x96, 0xb8, 0x79, 0x96, 0xb4,
+ 0x75, 0x92, 0xb1, 0x72, 0x8f, 0xaf, 0x70, 0x8d, 0xab, 0x6c, 0x89, 0xa7, 0x68, 0x85, 0xa2, 0x61,
+ 0x7f, 0x9c, 0x5b, 0x79, 0x9a, 0x57, 0x76, 0x9b, 0x56, 0x75, 0xb8, 0x77, 0x8f, 0xbb, 0x7a, 0x92,
+ 0xbc, 0x7c, 0x96, 0xbc, 0x7c, 0x96, 0xbb, 0x7b, 0x96, 0xb9, 0x79, 0x94, 0xb5, 0x76, 0x91, 0xb2,
+ 0x73, 0x8e, 0xae, 0x6f, 0x8c, 0xac, 0x6d, 0x8a, 0xa4, 0x65, 0x82, 0xa0, 0x61, 0x7e, 0x9b, 0x5a,
+ 0x78, 0x96, 0x55, 0x73, 0x94, 0x51, 0x70, 0x97, 0x52, 0x71, 0xb9, 0x75, 0x8c, 0xba, 0x79, 0x91,
+ 0xbd, 0x7c, 0x94, 0xbb, 0x7b, 0x95, 0xba, 0x7a, 0x95, 0xb8, 0x78, 0x93, 0xb5, 0x75, 0x90, 0xb0,
+ 0x71, 0x8c, 0xad, 0x6e, 0x8b, 0xaa, 0x6b, 0x88, 0xa3, 0x64, 0x81, 0xa0, 0x5f, 0x7d, 0x9b, 0x5a,
+ 0x78, 0x97, 0x54, 0x73, 0x95, 0x52, 0x71, 0x99, 0x53, 0x75
+};
+
+const uint8_t image_data_1[IMAGE_FILE_LENGHT] =
+{
+ 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
+ 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31,
+ 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e,
+ 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0xa9, 0xd6, 0xb8, 0xa7, 0xd4,
+ 0xba, 0xaa, 0xd7, 0xbd, 0xac, 0xd9, 0xbc, 0xab, 0xd8, 0xbc, 0xab, 0xd7, 0xba, 0xa9, 0xd5, 0xb5,
+ 0xa4, 0xd0, 0xaf, 0x9e, 0xca, 0x98, 0x89, 0xb2, 0x8d, 0x7e, 0xa5, 0x7c, 0x6d, 0x94, 0x70, 0x62,
+ 0x86, 0x6b, 0x5d, 0x80, 0x6c, 0x5e, 0x81, 0x6e, 0x60, 0x81, 0xb9, 0xac, 0xd8, 0xc2, 0xb2, 0xdf,
+ 0xbe, 0xb1, 0xdd, 0xbd, 0xad, 0xda, 0xbb, 0xae, 0xda, 0xba, 0xad, 0xd9, 0xb7, 0xaa, 0xd6, 0xb2,
+ 0xa5, 0xd1, 0xae, 0xa1, 0xcc, 0x9d, 0x8e, 0xb7, 0x8f, 0x80, 0xa7, 0x80, 0x72, 0x96, 0x77, 0x69,
+ 0x8d, 0x72, 0x64, 0x87, 0x6e, 0x60, 0x83, 0x6c, 0x5e, 0x7f, 0xbe, 0xb1, 0xdd, 0xc4, 0xb7, 0xe3,
+ 0xc2, 0xb5, 0xe1, 0xc1, 0xb4, 0xe0, 0xc0, 0xb3, 0xdf, 0xbe, 0xb3, 0xde, 0xbb, 0xb0, 0xdb, 0xb7,
+ 0xac, 0xd7, 0xb3, 0xa8, 0xd2, 0xa0, 0x91, 0xba, 0x93, 0x84, 0xab, 0x83, 0x75, 0x99, 0x78, 0x6a,
+ 0x8e, 0x72, 0x64, 0x87, 0x6d, 0x5f, 0x82, 0x6b, 0x5d, 0x7e
+};
+
+const uint8_t image_data_2[] =
+{
+ 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
+ 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31,
+ 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e,
+ 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a,
+ 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x1f, 0xee, 0x1d, 0x00, 0x00,
+ 0x00, 0x1f, 0xee, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x04, 0x04, 0x04,
+ 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a,
+ 0x0a, 0xfe, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe,
+ 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a,
+ 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0xdd, 0xfa, 0x03, 0xdd, 0xfa,
+ 0x03, 0xdd, 0xfa, 0x03, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00
+};
+
+Adafruit_NeoPixel top_row(NUM_PIXELS, TOP_ROW, NEO_GRB);
+Adafruit_NeoPixel mid_row(NUM_PIXELS, MID_ROW, NEO_GRB);
+Adafruit_NeoPixel bot_row(NUM_PIXELS, BOT_ROW, NEO_GRB);
+
+void setup()
+{
+ pinMode(TOP_ROW, OUTPUT);
+ pinMode(MID_ROW, OUTPUT);
+ pinMode(BOT_ROW, OUTPUT);
+
+ // LED strip initialization
+ top_row.begin();
+ mid_row.begin();
+ bot_row.begin();
+}
+
+void loop()
+{
+ uint8_t frame_buffer[3][NUM_PIXELS][3] = {{{0}}};
+
+ render_image(frame_buffer, image_data_2);
+ display_rgb(frame_buffer);
+}
+
+int render_image(uint8_t buff[3][NUM_PIXELS][3], const uint8_t image[])
+{
+ if (buff == NULL || image == NULL)
+ return -1;
+
+ for (uint8_t row = 0; row < 3; row++)
+ {
+ for (uint8_t col = 0; col < NUM_PIXELS; col++)
+ {
+ for (uint8_t i = 0; i < 3; i++)
+ {
+ buff[row][col][i] = image[PPM_HEADER_LENGHT + row * NUM_PIXELS * 3 + col * 3 + i];
+ }
+ }
+ }
+
+ return 0;
+}
+
+int display_rgb(uint8_t buff[3][NUM_PIXELS][3])
+{
+ if (buff == NULL)
+ return -1;
+
+ for (uint8_t col; col < NUM_PIXELS; col++)
+ {
+ top_row.setPixelColor(col, top_row.Color(buff[0][col][0], buff[0][col][1], buff[0][col][2]));
+ mid_row.setPixelColor(col, mid_row.Color(buff[1][col][0], buff[1][col][1], buff[1][col][2]));
+ bot_row.setPixelColor(col, bot_row.Color(buff[2][col][0], buff[2][col][1], buff[2][col][2]));
+ }
+
+ top_row.show();
+ mid_row.show();
+ bot_row.show();
+
+ return 0;
+}
--- /dev/null
+P6
+# Created by GIMP version 2.10.22 PNM plug-in
+16 3
+255
+¹x\90¼{\93¾~\98¾~\98¼}\98º{\96¸y\96´u\92±r\8f¯p\8d«l\89§h\85¢a\7f\9c[y\9aWv\9bVu¸w\8f»z\92¼|\96¼|\96»{\96¹y\94µv\91²s\8e®o\8c¬m\8a¤e\82 a~\9bZx\96Us\94Qp\97Rq¹u\8cºy\91½|\94»{\95ºz\95¸x\93µu\90°q\8cn\8bªk\88£d\81 _}\9bZx\97Ts\95Rq\99Su
\ No newline at end of file
--- /dev/null
+0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
+0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31,
+0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e,
+0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0xa9, 0xd6, 0xb8, 0xa7, 0xd4,
+0xba, 0xaa, 0xd7, 0xbd, 0xac, 0xd9, 0xbc, 0xab, 0xd8, 0xbc, 0xab, 0xd7, 0xba, 0xa9, 0xd5, 0xb5,
+0xa4, 0xd0, 0xaf, 0x9e, 0xca, 0x98, 0x89, 0xb2, 0x8d, 0x7e, 0xa5, 0x7c, 0x6d, 0x94, 0x70, 0x62,
+0x86, 0x6b, 0x5d, 0x80, 0x6c, 0x5e, 0x81, 0x6e, 0x60, 0x81, 0xb9, 0xac, 0xd8, 0xc2, 0xb2, 0xdf,
+0xbe, 0xb1, 0xdd, 0xbd, 0xad, 0xda, 0xbb, 0xae, 0xda, 0xba, 0xad, 0xd9, 0xb7, 0xaa, 0xd6, 0xb2,
+0xa5, 0xd1, 0xae, 0xa1, 0xcc, 0x9d, 0x8e, 0xb7, 0x8f, 0x80, 0xa7, 0x80, 0x72, 0x96, 0x77, 0x69,
+0x8d, 0x72, 0x64, 0x87, 0x6e, 0x60, 0x83, 0x6c, 0x5e, 0x7f, 0xbe, 0xb1, 0xdd, 0xc4, 0xb7, 0xe3,
+0xc2, 0xb5, 0xe1, 0xc1, 0xb4, 0xe0, 0xc0, 0xb3, 0xdf, 0xbe, 0xb3, 0xde, 0xbb, 0xb0, 0xdb, 0xb7,
+0xac, 0xd7, 0xb3, 0xa8, 0xd2, 0xa0, 0x91, 0xba, 0x93, 0x84, 0xab, 0x83, 0x75, 0x99, 0x78, 0x6a,
+0x8e, 0x72, 0x64, 0x87, 0x6d, 0x5f, 0x82, 0x6b, 0x5d, 0x7e
\ No newline at end of file
--- /dev/null
+https://www.tinkercad.com/things/4uzv4lu12yT
+++ /dev/null
-#define LED 9
-uint32_t br = 0;
-void setup() {
- pinMode(LED, OUTPUT);
-}
-void loop() {
- for (uint32_t x = 0; x < 100; x++) {
- //br = (x*250)/100; // Gamma - NO
- //br = (x*x)/40; // Gamma - 2
- br = (x*x*x)/4000; // Gamma - 3
- analogWrite(LED,br);
- delay(20);
- }
- for (uint32_t x = 100; x > 0; x--) {
- //br = (x*250)/100; // Gamma - NO
- //br = (x*x)/40; // Gamma - 2
- br = (x*x*x)/4000; // Gamma - 3
- analogWrite(LED,br);
- delay(20);
- }
-}
+++ /dev/null
-#include <Adafruit_NeoPixel.h>
-#define LED_PIN 6
-#define LED_ROW 8
-#define LED_COL 8
-#define LED_COUNT (LED_ROW * LED_COL)
-
-Adafruit_NeoPixel matrix(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
-
-uint32_t brightness = 0;
-
-void setup() {
- matrix.begin();
- matrix.show();
- matrix.setBrightness(255);
-}
-
-void loop() {
- for (uint32_t x = 0; x < 100; x++) {
- //brightness = (x*250)/100; // Gamma - NO
- //brightness = (x*x)/40; // Gamma - 2
- brightness = (x*x*x)/4000; // Gamma - 3
- matrix.setPixelColor(0, (uint8_t)brightness, 0, 0);
- matrix.show();
- delay(20);
- }
- for (uint32_t x = 100; x > 0; x--) {
- //brightness = (x*250)/100; // Gamma - NO
- //brightness = (x*x)/40; // Gamma - 2
- brightness = (x*x*x)/4000; // Gamma - 3
- matrix.setPixelColor(0, (uint8_t)brightness, 0, 0);
- matrix.show();
- delay(20);
- }
-}
+++ /dev/null
-#include <Adafruit_NeoPixel.h>
-#define LED_PIN 6
-#define LED_ROW 8
-#define LED_COL 8
-#define LED_COUNT (LED_ROW * LED_COL)
-
-Adafruit_NeoPixel matrix(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
-
-uint32_t brightness = 0;
-
-// This way the LUT can be at the bottom of the code
-extern const uint8_t gamma[];
-
-// L - emitted light by the LED
-// B - perceived brightness by the EYE
-
-// Single color
-// B=L^(1/gamma)
-// L=B^(gamma)
-
-// RGB MultiColor
-// B=(Red^gamma+Green^gamma+Blue^gamma)^(1/gamma)
-
-void setup() {
- matrix.begin();
- matrix.show();
- matrix.setBrightness(255);
-}
-
-void loop() {
- for (uint8_t x = 0; x < 100; x++) {
- setRGB(0, 100, x, 0);
- matrix.show();
- delay(20);
- }
- for (uint8_t x = 100; x > 0; x--) {
- setRGB(0, x, 100, 0);
- matrix.show();
- delay(20);
- }
- for (uint8_t x = 0; x < 100; x++) {
- setRGB(0, x, 100, 0);
- matrix.show();
- delay(20);
- }
- for (uint8_t x = 100; x > 0; x--) {
- setRGB(0, 100, x, 0);
- matrix.show();
- delay(20);
- }
-}
-
-void setRGB(uint8_t pixelNumber, uint8_t red, uint8_t green, uint8_t blue) {
- matrix.setPixelColor(pixelNumber,
- pgm_read_byte(&gamma[red]),
- pgm_read_byte(&gamma[green]),
- pgm_read_byte(&gamma[blue]));
-}
-
-// Gamma 2.2
-
-const uint8_t PROGMEM gamma[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
- 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6,
- 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12,
- 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19,
- 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, 29,
- 30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41,
- 42, 43, 43, 44, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55,
- 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
- 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 87, 88, 89, 90,
- 91, 93, 94, 95, 97, 98, 99, 100, 102, 103, 105, 106, 107, 109, 110, 111,
- 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135,
- 137, 138, 140, 141, 143, 145, 146, 148, 149, 151, 153, 154, 156, 158, 159, 161,
- 163, 165, 166, 168, 170, 172, 173, 175, 177, 179, 181, 182, 184, 186, 188, 190,
- 192, 194, 196, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221,
- 223, 225, 227, 229, 231, 234, 236, 238, 240, 242, 244, 246, 248, 251, 253, 255
-};
-
-
-// Gamma 1.8
-/*
- const uint8_t PROGMEM gamma[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2,
- 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6,
- 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12,
- 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 21,
- 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31,
- 32, 32, 33, 34, 35, 35, 36, 37, 38, 38, 39, 40, 41, 41, 42, 43,
- 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 53, 54, 55, 56, 57,
- 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
- 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90,
- 91, 92, 93, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 107, 108, 109,
- 110, 111, 113, 114, 115, 116, 118, 119, 120, 122, 123, 124, 126, 127, 128, 129,
- 131, 132, 134, 135, 136, 138, 139, 140, 142, 143, 145, 146, 147, 149, 150, 152,
- 153, 154, 156, 157, 159, 160, 162, 163, 165, 166, 168, 169, 171, 172, 174, 175,
- 177, 178, 180, 181, 183, 184, 186, 188, 189, 191, 192, 194, 195, 197, 199, 200,
- 202, 204, 205, 207, 208, 210, 212, 213, 215, 217, 218, 220, 222, 224, 225, 227,
- 229, 230, 232, 234, 236, 237, 239, 241, 243, 244, 246, 248, 250, 251, 253, 255
- };
-*/
-
-// Gamma 2.8
-/*
- const uint8_t PROGMEM gamma[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
- 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
- 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
- 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
- 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
- 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
- 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
- 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
- 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
- 90, 92, 93, 95, 96, 98, 99, 101, 102, 104, 105, 107, 109, 110, 112, 114,
- 115, 117, 119, 120, 122, 124, 126, 127, 129, 131, 133, 135, 137, 138, 140, 142,
- 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 167, 169, 171, 173, 175,
- 177, 180, 182, 184, 186, 189, 191, 193, 196, 198, 200, 203, 205, 208, 210, 213,
- 215, 218, 220, 223, 225, 228, 231, 233, 236, 239, 241, 244, 247, 249, 252, 255
- };
-*/
+++ /dev/null
-void setup() {
- DDRB |= (1 << PB5); // Set digital pin 13 (Port B Pin 5) to output
-}
-
-void loop() {
- PORTB |= (1 << PB5); // Set digital pin 13 (Port B Pin 5) high
- _delay_ms(500); // wait 500ms
- PORTB &= ~(1 << PB5); // Set digital pin 13 (Port B Pin 5) low
- _delay_ms(500); // wait 500ms
-
- //PORTB ^= (1 << PB5); // Toggle digital pin 13 (Port B Pin 5)
-}
+++ /dev/null
-<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\r
-<WORKSPACE>\r
- <FRAME activewindow="0">\r
- <PLACEMENT>2c0000000000000001000000ffffffffffffffffffffffffffffffff670000001a000000de06000010040000</PLACEMENT>\r
- <WINDOW type="default" module="ISIS"/>\r
- </FRAME>\r
- <MODULE name="VSMDEBUG">\r
- <PWI>\r
- <POPUP w="668" x="166" flags="00008003" y="105" h="210" pid="0" iid="-1">\r
- <PROPERTIES>\r
- <ITEM name="Message Column Width">524</ITEM>\r
- <ITEM name="ShowGrid">No</ITEM>\r
- <ITEM name="Source Column Width">107</ITEM>\r
- <ITEM name="Version">100</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="350" x="6" flags="00000032" y="114" h="100" pid="1" iid="-1">\r
- <PROPERTIES>\r
- <ITEM name="Address Column Width">87</ITEM>\r
- <ITEM name="AutoResize">No</ITEM>\r
- <ITEM name="Gridlines">Yes</ITEM>\r
- <ITEM name="Name Column Width">87</ITEM>\r
- <ITEM name="ShowAddresses">Yes</ITEM>\r
- <ITEM name="ShowPreviousValues">No</ITEM>\r
- <ITEM name="ShowTypes">No</ITEM>\r
- <ITEM name="ShowWatchPoint">Yes</ITEM>\r
- <ITEM name="TriggerMode">0</ITEM>\r
- <ITEM name="Value Column Width">87</ITEM>\r
- <ITEM name="Version">100</ITEM>\r
- <ITEM name="Watch Expression Column Width">87</ITEM>\r
- <ITEM name="nItems">0</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="226" x="6" flags="00000008" y="114" h="215" pid="3" iid="1">\r
- <PROPERTIES/>\r
- </POPUP>\r
- <POPUP w="1" x="6" flags="0000000a" y="114" h="1" pid="10" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000000</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="1" x="6" flags="0000000a" y="114" h="2" pid="6" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000000</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="1" x="6" flags="0000000a" y="114" h="2" pid="7" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000000</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="16" x="159" flags="00000000" y="285" h="32" pid="14" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000000</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="1" x="6" flags="0000000a" y="114" h="2" pid="4" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000100</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="1" x="6" flags="0000000a" y="114" h="1" pid="13" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="DataType">2</ITEM>\r
- <ITEM name="DispChars">Yes</ITEM>\r
- <ITEM name="DispFormat">2</ITEM>\r
- <ITEM name="ShowChanges">Yes</ITEM>\r
- <ITEM name="ShowToolTips">Yes</ITEM>\r
- <ITEM name="TopLineAddress">00000020</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="944" x="7" flags="0000002b" y="135" h="724" pid="1" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="CaseSensitive">No</ITEM>\r
- <ITEM name="DISPADDRS">Yes</ITEM>\r
- <ITEM name="DISPLNUMS">No</ITEM>\r
- <ITEM name="DISPOPCODES">No</ITEM>\r
- <ITEM name="FIXUPBPTS">Yes</ITEM>\r
- <ITEM name="WordsOnly">No</ITEM>\r
- <ITEM name="nBreakpoints">0</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- <POPUP w="1910" x="6" flags="0000000b" y="899" h="121" pid="2" iid="1">\r
- <PROPERTIES>\r
- <ITEM name="Address Column Width">636</ITEM>\r
- <ITEM name="AutoResize">No</ITEM>\r
- <ITEM name="Gridlines">Yes</ITEM>\r
- <ITEM name="Name Column Width">636</ITEM>\r
- <ITEM name="ShowAddresses">Yes</ITEM>\r
- <ITEM name="ShowGlobals">Yes</ITEM>\r
- <ITEM name="ShowPreviousValues">No</ITEM>\r
- <ITEM name="ShowTypes">No</ITEM>\r
- <ITEM name="ShowWatchPoint">No</ITEM>\r
- <ITEM name="TriggerMode">0</ITEM>\r
- <ITEM name="Value Column Width">636</ITEM>\r
- <ITEM name="Version">100</ITEM>\r
- <ITEM name="nItems">0</ITEM>\r
- </PROPERTIES>\r
- </POPUP>\r
- </PWI>\r
- </MODULE>\r
-</WORKSPACE>\r
+++ /dev/null
-#include <inttypes.h>
-
-#define A1_PIN 9
-#define A2_PIN 8
-#define B1_PIN 11
-#define B2_PIN 10
-#define EN_PIN 12
-
-#define STEP_TIME 1000 // ms
-
-//#define FULL_STEP
-#define HALF_STEP
-
-#ifdef FULL_STEP
-#define NUM_STEPS 4
-const uint8_t coil_current[NUM_STEPS][4] =
-{
- {1, 0, 0, 1},
- {1, 1, 0, 0},
- {0, 1, 1, 0},
- {0, 0, 1, 1}
-};
-#endif
-
-#ifdef HALF_STEP
-#define NUM_STEPS 8
-const uint8_t coil_current[NUM_STEPS][4] =
-{
- {1, 0, 0, 1},
- {1, 0, 0, 0},
- {1, 1, 0, 0},
- {0, 1, 0, 0},
- {0, 1, 1, 0},
- {0, 0, 1, 0},
- {0, 0, 1, 1},
- {0, 0, 0, 1}
-};
-#endif
-
-const uint8_t stepper_pins[4] = {A2_PIN, A1_PIN, B1_PIN, B2_PIN};
-
-void setup()
-{
- for (uint8_t i = 0; i < 4; i++)
- {
- pinMode(stepper_pins[i], OUTPUT);
- }
- pinMode(EN_PIN, OUTPUT);
- digitalWrite(EN_PIN, HIGH);
-}
-
-void loop()
-{
- static uint8_t step = 0;
-
- for (uint8_t i = 0; i < 4; i++)
- {
- digitalWrite(stepper_pins[i], coil_current[step][i]);
- }
-
- step++;
- if (step >= NUM_STEPS)
- {
- step = 0;
- }
-
- delay(STEP_TIME);
-}\r
+++ /dev/null
-#include <inttypes.h>
-
-#define A1_PIN 9
-#define A2_PIN 8
-#define B1_PIN 11
-#define B2_PIN 10
-#define EN_PIN 12
-
-#define STEP_TIME 200 // ms, max 1000
-
-#define FULL_STEP
-//#define HALF_STEP
-
-#ifdef FULL_STEP
-#define NUM_STEPS 4
-const uint8_t coil_current[NUM_STEPS][4] =
-{
- {1, 0, 0, 1},
- {1, 1, 0, 0},
- {0, 1, 1, 0},
- {0, 0, 1, 1}
-};
-#endif
-
-#ifdef HALF_STEP
-#define NUM_STEPS 8
-const uint8_t coil_current[NUM_STEPS][4] =
-{
- {1, 0, 0, 1},
- {1, 0, 0, 0},
- {1, 1, 0, 0},
- {0, 1, 0, 0},
- {0, 1, 1, 0},
- {0, 0, 1, 0},
- {0, 0, 1, 1},
- {0, 0, 0, 1}
-};
-#endif
-
-void timer1_init(void);
-void stepper_init(void);
-
-const uint8_t stepper_pins[4] = {A2_PIN, A1_PIN, B1_PIN, B2_PIN};
-
-void setup()
-{
- stepper_init();
- timer1_init();
-}
-
-void loop()
-{}
-
-void timer1_init(void)
-{
- // Disable interrupts during timer configuration
- noInterrupts();
- // Select CTC mode (4) and set the prescaler to divide the clock by 256
- // resulting in timer frequency of 62.5 kHz
- TCCR1A = 0;
- TCCR1B = (1 << WGM12) | (1 << CS12);
- // Enable interrupt when reaching the maximum value (OCR1A)
- TIMSK1 = (1 << OCIE1A);
- // Set the timer period to 50 ms (50 * 62.5 = 3125)
- OCR1A = (int) STEP_TIME * 62.5;
- // Reset OC register B and the input capture register. They are not used
- ICR1 = OCR1B = 0;
- // Reset the counter register
- TCNT1 = 0;
- // Enable inerrupts
- interrupts();
-}
-
-ISR(TIMER1_COMPA_vect)
-{
- static volatile uint8_t step = 0;
-
- for (uint8_t i = 0; i < 4; i++)
- {
- digitalWrite(stepper_pins[i], coil_current[step][i]);
- }
-
- step++;
- if (step >= NUM_STEPS)
- {
- step = 0;
- }
-}
-
-void stepper_init(void)
-{
- for (uint8_t i = 0; i < 4; i++)
- {
- pinMode(stepper_pins[i], OUTPUT);
- }
- pinMode(EN_PIN, OUTPUT);
- digitalWrite(EN_PIN, HIGH);
-}
-\r
+++ /dev/null
-#include <Adafruit_NeoPixel.h>
-#include <inttypes.h>
-
-#define NUM_PIXELS 16
-
-#define TOP_ROW 4
-#define MID_ROW 3
-#define BOT_ROW 2
-
-#define PPM_HEADER_LENGHT 58
-#define IMAGE_FILE_LENGHT 202
-
-/*
-typedef enum {RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN} simple_color_t;
-int display_enum(simple_color_t buff[]);
-*/
-
-int render_image(uint8_t buff[3][NUM_PIXELS][3], const uint8_t image[]);
-int display_rgb(uint8_t buff[3][NUM_PIXELS][3]);
-
-const uint8_t image_data_0[IMAGE_FILE_LENGHT] =
-{
- 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
- 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31,
- 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e,
- 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0x78, 0x90, 0xbc, 0x7b, 0x93,
- 0xbe, 0x7e, 0x98, 0xbe, 0x7e, 0x98, 0xbc, 0x7d, 0x98, 0xba, 0x7b, 0x96, 0xb8, 0x79, 0x96, 0xb4,
- 0x75, 0x92, 0xb1, 0x72, 0x8f, 0xaf, 0x70, 0x8d, 0xab, 0x6c, 0x89, 0xa7, 0x68, 0x85, 0xa2, 0x61,
- 0x7f, 0x9c, 0x5b, 0x79, 0x9a, 0x57, 0x76, 0x9b, 0x56, 0x75, 0xb8, 0x77, 0x8f, 0xbb, 0x7a, 0x92,
- 0xbc, 0x7c, 0x96, 0xbc, 0x7c, 0x96, 0xbb, 0x7b, 0x96, 0xb9, 0x79, 0x94, 0xb5, 0x76, 0x91, 0xb2,
- 0x73, 0x8e, 0xae, 0x6f, 0x8c, 0xac, 0x6d, 0x8a, 0xa4, 0x65, 0x82, 0xa0, 0x61, 0x7e, 0x9b, 0x5a,
- 0x78, 0x96, 0x55, 0x73, 0x94, 0x51, 0x70, 0x97, 0x52, 0x71, 0xb9, 0x75, 0x8c, 0xba, 0x79, 0x91,
- 0xbd, 0x7c, 0x94, 0xbb, 0x7b, 0x95, 0xba, 0x7a, 0x95, 0xb8, 0x78, 0x93, 0xb5, 0x75, 0x90, 0xb0,
- 0x71, 0x8c, 0xad, 0x6e, 0x8b, 0xaa, 0x6b, 0x88, 0xa3, 0x64, 0x81, 0xa0, 0x5f, 0x7d, 0x9b, 0x5a,
- 0x78, 0x97, 0x54, 0x73, 0x95, 0x52, 0x71, 0x99, 0x53, 0x75
-};
-
-const uint8_t image_data_1[IMAGE_FILE_LENGHT] =
-{
- 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
- 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31,
- 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e,
- 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0xa9, 0xd6, 0xb8, 0xa7, 0xd4,
- 0xba, 0xaa, 0xd7, 0xbd, 0xac, 0xd9, 0xbc, 0xab, 0xd8, 0xbc, 0xab, 0xd7, 0xba, 0xa9, 0xd5, 0xb5,
- 0xa4, 0xd0, 0xaf, 0x9e, 0xca, 0x98, 0x89, 0xb2, 0x8d, 0x7e, 0xa5, 0x7c, 0x6d, 0x94, 0x70, 0x62,
- 0x86, 0x6b, 0x5d, 0x80, 0x6c, 0x5e, 0x81, 0x6e, 0x60, 0x81, 0xb9, 0xac, 0xd8, 0xc2, 0xb2, 0xdf,
- 0xbe, 0xb1, 0xdd, 0xbd, 0xad, 0xda, 0xbb, 0xae, 0xda, 0xba, 0xad, 0xd9, 0xb7, 0xaa, 0xd6, 0xb2,
- 0xa5, 0xd1, 0xae, 0xa1, 0xcc, 0x9d, 0x8e, 0xb7, 0x8f, 0x80, 0xa7, 0x80, 0x72, 0x96, 0x77, 0x69,
- 0x8d, 0x72, 0x64, 0x87, 0x6e, 0x60, 0x83, 0x6c, 0x5e, 0x7f, 0xbe, 0xb1, 0xdd, 0xc4, 0xb7, 0xe3,
- 0xc2, 0xb5, 0xe1, 0xc1, 0xb4, 0xe0, 0xc0, 0xb3, 0xdf, 0xbe, 0xb3, 0xde, 0xbb, 0xb0, 0xdb, 0xb7,
- 0xac, 0xd7, 0xb3, 0xa8, 0xd2, 0xa0, 0x91, 0xba, 0x93, 0x84, 0xab, 0x83, 0x75, 0x99, 0x78, 0x6a,
- 0x8e, 0x72, 0x64, 0x87, 0x6d, 0x5f, 0x82, 0x6b, 0x5d, 0x7e
-};
-
-const uint8_t image_data_2[] =
-{
- 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
- 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31,
- 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e,
- 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a,
- 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x1f, 0xee, 0x1d, 0x00, 0x00,
- 0x00, 0x1f, 0xee, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x04, 0x04, 0x04,
- 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a,
- 0x0a, 0xfe, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe,
- 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a,
- 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0xdd, 0xfa, 0x03, 0xdd, 0xfa,
- 0x03, 0xdd, 0xfa, 0x03, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00
-};
-
-Adafruit_NeoPixel top_row(NUM_PIXELS, TOP_ROW, NEO_GRB);
-Adafruit_NeoPixel mid_row(NUM_PIXELS, MID_ROW, NEO_GRB);
-Adafruit_NeoPixel bot_row(NUM_PIXELS, BOT_ROW, NEO_GRB);
-
-void setup()
-{
- pinMode(TOP_ROW, OUTPUT);
- pinMode(MID_ROW, OUTPUT);
- pinMode(BOT_ROW, OUTPUT);
-
- // LED strip initialization
- top_row.begin();
- mid_row.begin();
- bot_row.begin();
-}
-
-void loop()
-{
- uint8_t frame_buffer[3][NUM_PIXELS][3] = {{{0}}};
-
- render_image(frame_buffer, image_data_2);
- display_rgb(frame_buffer);
-}
-
-int render_image(uint8_t buff[3][NUM_PIXELS][3], const uint8_t image[])
-{
- if (buff == NULL || image == NULL)
- return -1;
-
- for (uint8_t row = 0; row < 3; row++)
- {
- for (uint8_t col = 0; col < NUM_PIXELS; col++)
- {
- for (uint8_t i = 0; i < 3; i++)
- {
- buff[row][col][i] = image[PPM_HEADER_LENGHT + row * NUM_PIXELS * 3 + col * 3 + i];
- }
- }
- }
-
- return 0;
-}
-
-int display_rgb(uint8_t buff[3][NUM_PIXELS][3])
-{
- if (buff == NULL)
- return -1;
-
- for (uint8_t col; col < NUM_PIXELS; col++)
- {
- top_row.setPixelColor(col, top_row.Color(buff[0][col][0], buff[0][col][1], buff[0][col][2]));
- mid_row.setPixelColor(col, mid_row.Color(buff[1][col][0], buff[1][col][1], buff[1][col][2]));
- bot_row.setPixelColor(col, bot_row.Color(buff[2][col][0], buff[2][col][1], buff[2][col][2]));
- }
-
- top_row.show();
- mid_row.show();
- bot_row.show();
-
- return 0;
-}
+++ /dev/null
-P6
-# Created by GIMP version 2.10.22 PNM plug-in
-16 3
-255
-¹x\90¼{\93¾~\98¾~\98¼}\98º{\96¸y\96´u\92±r\8f¯p\8d«l\89§h\85¢a\7f\9c[y\9aWv\9bVu¸w\8f»z\92¼|\96¼|\96»{\96¹y\94µv\91²s\8e®o\8c¬m\8a¤e\82 a~\9bZx\96Us\94Qp\97Rq¹u\8cºy\91½|\94»{\95ºz\95¸x\93µu\90°q\8cn\8bªk\88£d\81 _}\9bZx\97Ts\95Rq\99Su
\ No newline at end of file
+++ /dev/null
-0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20,
-0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31,
-0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e,
-0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0xa9, 0xd6, 0xb8, 0xa7, 0xd4,
-0xba, 0xaa, 0xd7, 0xbd, 0xac, 0xd9, 0xbc, 0xab, 0xd8, 0xbc, 0xab, 0xd7, 0xba, 0xa9, 0xd5, 0xb5,
-0xa4, 0xd0, 0xaf, 0x9e, 0xca, 0x98, 0x89, 0xb2, 0x8d, 0x7e, 0xa5, 0x7c, 0x6d, 0x94, 0x70, 0x62,
-0x86, 0x6b, 0x5d, 0x80, 0x6c, 0x5e, 0x81, 0x6e, 0x60, 0x81, 0xb9, 0xac, 0xd8, 0xc2, 0xb2, 0xdf,
-0xbe, 0xb1, 0xdd, 0xbd, 0xad, 0xda, 0xbb, 0xae, 0xda, 0xba, 0xad, 0xd9, 0xb7, 0xaa, 0xd6, 0xb2,
-0xa5, 0xd1, 0xae, 0xa1, 0xcc, 0x9d, 0x8e, 0xb7, 0x8f, 0x80, 0xa7, 0x80, 0x72, 0x96, 0x77, 0x69,
-0x8d, 0x72, 0x64, 0x87, 0x6e, 0x60, 0x83, 0x6c, 0x5e, 0x7f, 0xbe, 0xb1, 0xdd, 0xc4, 0xb7, 0xe3,
-0xc2, 0xb5, 0xe1, 0xc1, 0xb4, 0xe0, 0xc0, 0xb3, 0xdf, 0xbe, 0xb3, 0xde, 0xbb, 0xb0, 0xdb, 0xb7,
-0xac, 0xd7, 0xb3, 0xa8, 0xd2, 0xa0, 0x91, 0xba, 0x93, 0x84, 0xab, 0x83, 0x75, 0x99, 0x78, 0x6a,
-0x8e, 0x72, 0x64, 0x87, 0x6d, 0x5f, 0x82, 0x6b, 0x5d, 0x7e
\ No newline at end of file
+++ /dev/null
-https://www.tinkercad.com/things/4uzv4lu12yT
+++ /dev/null
-/*
- Timer 1 is set to generate Compare Match Interrupt with frequency 1Hz
- The counter counts with frequency 16MHz/1024 = 15.625kHz
- For 1s the counter will reach value of [15.625kHz*1s - 1] = [15625 - 1] = 15624
- This value is set as compare value so that when counter reaches it
- it will generate Interrupt with Period exactly 1s => Frequency 1Hz
- LED attached on pin 13 is TOGGLED with this frequency of 1Hz so it stays 1s on and 1s off
-*/
-
-volatile boolean toggle = 0;
-
-void setup() {
- pinMode(13, OUTPUT); // Set pin 13 as output
- noInterrupts(); //cli(); // Stop reception of interrupts
-
- // Set Timer 1 Control registers and counter to 0
- TCCR1A = 0;
- TCCR1B = 0;
- TIMSK1 = 0;
- TCNT1 = 0;
-
- // Set compare match value = Fclk_io / (Fout * Prescaler) - 1
- OCR1A = 15624; // = (16MHz) / (1 * 1024) - 1
- TIMSK1 |= (1 << OCIE1A); // Enable compare match interrupt
-
- // Set Timer 1 Mode of operation to Clear Timer on Compare Match (CTC -> Mode 4)
- TCCR1B |= (1 << WGM12); // Mode 4
-
- // Set Timer 1 Clock prescaler and source so that the timer starts counting
- TCCR1B |= (1 << CS12) | (1 << CS10); // Set prescaler to 1024 (=> enable the clock)
-
- interrupts(); //sei(); // Allow reception of interrupts
-}
-
-void loop() {
- // put your main code here, to run repeatedly:
-}
-
-/*
- Timer1 Interrupt Service Routine (ISR)
- Toggle pin 13 (LED) every 1s
- Generates pulse wave of frequency 1Hz/2 = 0.5Hz
- Takes two cycles for full wave - toggle high then after 1s toggle low after 1s repeat
-*/
-ISR(TIMER1_COMPA_vect) {
- if (toggle == 1) {
- digitalWrite(13, HIGH);
- toggle = 0;
- }
- else {
- digitalWrite(13, LOW);
- toggle = 1;
- }
-}
+++ /dev/null
-void setup() {
- // Set pin 13 to output
- pinMode(13, OUTPUT);
-
- // Stop reception of interrupts
- noInterrupts(); //cli();
-
- // Set PB1 to be an output (Pin-9 Arduino UNO)
- DDRB |= (1 << PB1);
-
- // Clear Timer/Counter Control Registers
- TCCR1A = 0;
- TCCR1B = 0;
- TIMSK1 = 0;
-
- // Set non-inverting mode - Table 15-3 (page 108)
- TCCR1A |= (1 << COM1A1);
- TCCR1A |= (1 << COM1B1);
-
- // Set Fast-PWM Mode (Mode 14) - Table 15-5 (page 109)
- TCCR1A |= (1 << WGM11);
- TCCR1B |= (1 << WGM12);
- TCCR1B |= (1 << WGM13);
-
- // Clear Timer 1 Counter
- TCNT1 = 0;
-
- // Set PWM frequency/top value - Output PWM 10kHz
- ICR1 = 199; // Fclk_io / (Fout * Prescaler) - 1
- OCR1A = 100; // Output OC1A will be ON for [OCR1A/(ICR1+1)]% of the time -> 100/(199+1) = 50%
- OCR1B = 50;
-
- // Enable compare match interrupt
- TIMSK1 |= (1 << OCIE1A);
- TIMSK1 |= (1 << OCIE1B);
- TIMSK1 |= (1 << TOIE1);
-
- // Set prescaler to 8 and starts PWM
- TCCR1B |= (1 << CS11);
-
- // Enables interrupts
- interrupts(); //sei();
-}
-
-void loop() {
- // Empty
-}
-
-//Timer1 Compare Match Interrupt turns OFF pin 13 (LED)
-ISR(TIMER1_COMPA_vect) {
- digitalWrite(13, LOW);
-}
-
-//Timer1 Compare Match Interrupt turns OFF pin 13 (LED)
-ISR(TIMER1_COMPB_vect) {
- //digitalWrite(13, LOW);
-}
-
-//Timer1 Overflow Interrupt turns ON pin 13 (LED)
-ISR(TIMER1_OVF_vect) {
- digitalWrite(13, HIGH);
-}
+++ /dev/null
-https://www.tinkercad.com/things/c8JLkjplQKy
+++ /dev/null
-volatile uint16_t var = 0;
-
-void setup()
-{
- noInterrupts(); // Забраняваме глобално прекъсванията //cli();
-
- // Зануляване на конфигурацията
- TCCR1A = 0;
- TCCR1B = 0;
- TCCR1C = 0;
- TCNT1 = 0;
- OCR1A = 0;
- OCR1B = 0;
- ICR1 = 0;
- TIMSK1 = 0;
- TIFR1 = 0;
-
- // Режим на таймера - 14 Fast-PWM
- TCCR1A = TCCR1A | (1 << WGM11);
- TCCR1B = TCCR1B | (1 << WGM12);
- TCCR1B = TCCR1B | (1 << WGM13);
- // TCCR1A |= (1 << WGM11);
- // TCCR1B = TCCR1B | (1 << WGM12) | (1 << WGM13);
-
- // Режим на изводите - неинв.
- TCCR1A = TCCR1A | (1 << COM1A1) | (1 << COM1B1);
-
- // Честота - 500Hz
- // Избираме Prescaler = 1
- ICR1 = 31999; // TOP = 16MHZ/(1*500Hz)-1 = 31999
-
- // Коеф. на запълване - 75%
- OCR1A = 23999; // DUTY = TOP * 75% = 31999*75% = 23999
-
- // Прекъсване - CM A
- TIMSK1 |= (1 << OCIE1A);
-
- // Пускане на таймера
- TCCR1B |= (1 << CS10);
-
- interrupts(); // Разрешаваме глобално прекъсванията //sei();
-}
-
-ISR(TIMER1_COMPA_vect)
-{
- var++;
-}
-
-void loop()
-{
-
-}
+++ /dev/null
-#define BTN_PIN 2
-
-volatile uint8_t timer_en = 0;
-
-void button_pressed_ISR(void);
-
-void setup()
-{
- // Stop reception of interrupts
- noInterrupts(); //cli();
-
- pinMode(BTN_PIN, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(BTN_PIN), button_pressed_ISR, FALLING);
-
- // Set PB1 to be an output (Pin9 Arduino UNO)
- DDRB |= (1 << PB1);
-
- // Clear Timer/Counter Control Registers
- TCCR1A = 0;
- TCCR1B = 0;
- TIMSK1 = 0;
-
- // Set non-inverting mode - Table 15-3 (page 108)
- TCCR1A |= (1 << COM1A1);
-
- // Set Fast-PWM Mode (Mode 14) - Table 15-5 (page 109)
- TCCR1A |= (1 << WGM11);
- TCCR1B |= (1 << WGM12);
- TCCR1B |= (1 << WGM13);
-
- // Clear Timer 1 Counter
- TCNT1 = 0;
-
- // Set PWM frequency/top value - Output PWM 1Hz
- ICR1 = 15625;
- OCR1A = 10000;
-
- // Enable interrupts
- interrupts();
-}
-
-void loop() {
- // some useless code here
- }
-
-void button_pressed_ISR(void)
-{
- if (timer_en)
- {
- timer_en = 0;
- // Disable the timer by selecting "none" as the clock source
- TCCR1B &= ~((1 << CS11) | (1 << CS12) | (1 << CS10));
- }
- else
- {
- timer_en = 1;
- // Enable the timer
- TCCR1B |= (1 << CS12) | (1 << CS10);
- TCCR1B &= ~(1 << CS11);
- }
-}
+++ /dev/null
-https://www.tinkercad.com/things/abCdiMvkJs6
+++ /dev/null
-#define DIP_SW_0 8
-#define DIP_SW_1 9
-#define DIP_SW_2 10
-#define DIP_SW_3 11
-
-#define BUTTON 2
-#define LED 13
-
-void button_ISR(void);
-
-volatile bool led_flag = false;
-
-void setup()
-{
- pinMode(DIP_SW_0, INPUT_PULLUP);
- pinMode(DIP_SW_1, INPUT_PULLUP);
- pinMode(DIP_SW_2, INPUT_PULLUP);
- pinMode(DIP_SW_3, INPUT_PULLUP);
- pinMode(BUTTON, INPUT_PULLUP);
- pinMode(LED, OUTPUT);
- digitalWrite(LED, LOW);
-
- attachInterrupt(digitalPinToInterrupt(BUTTON), button_ISR, FALLING);
-
- // Disable interrupts during timer configuration
- cli();
-
- // Zero the control and counter registers
- TCCR1A = TCCR1B = TIMSK1 = 0;
- TCNT1 = 0;
-
- // Select mode 15 (Fast PWM, TOP = OCR1A)
- TCCR1A |= (1 << WGM10);
- TCCR1A |= (1 << WGM11);
- TCCR1B |= (1 << WGM12);
- TCCR1B |= (1 << WGM13);
-
- // Set max counter value (frequency)
- OCR1A = 7811;
-
- // Enable timer overflow interrupt
- TIMSK1 |= (1 << TOIE1);
-
- // Set prescaler to 1024
- TCCR1B |= (1 << CS10) | (1 << CS12);
-
- // Enable interrupts
- sei();
-
- Serial.begin(9600);
-}
-
-void loop()
-{
- Serial.println(OCR1A);
- delay(1000);
-}
-
-ISR(TIMER1_OVF_vect)
-{
- digitalWrite(LED, led_flag);
- led_flag = !led_flag;
-}
-
-void button_ISR(void)
-{
- uint8_t f = ~PINB & 0x0F;
-
- if (f)
- {
- OCR1A = 16000000 / (1024 * f) - 1;
- }
-}
+++ /dev/null
- https://www.tinkercad.com/things/2g5g32R3Fb7
+++ /dev/null
-// Timer 1 - Mode 14
-// f = 10kHz ; δ = 25%
-
-void setup() {
-
- DDRB |= (1 << PB1);
-
- // Zero
- TCCR1A = 0;
- TCCR1B = 0;
-
- // Set stuff
- TCCR1A |= (1 << WGM11) | (1 << COM1A1);
- TCCR1B |= (1 << WGM13) | (1 << WGM12);
- ICR1 = 1599; // Period (TOP)
- OCR1A = 400; // Duty cycle
- TCCR1B |= (1 << CS10);
-
-}
-
-void loop() {
-
-}
+++ /dev/null
-// Timer 1 - Mode 14
-// f = 10kHz ; δ = 50%
-
-void setup() {
-
- DDRB |= (1 << PB1);
-
- // Zero
- TCCR1A = 0;
- TCCR1B = 0;
-
- // Set stuff
- TCCR1A |= (1 << WGM11) | (1 << COM1A1);
- TCCR1B |= (1 << WGM13) | (1 << WGM12);
- ICR1 = 1599; // Period (TOP)
- OCR1A = 800; // Duty cycle
- TCCR1B |= (1 << CS10);
-
-}
-
-void loop() {
-
-}
+++ /dev/null
-// Timer 1 - Mode 14
-// f = 2Hz ; δ = 25%
-
-void setup() {
-
- DDRB |= (1 << PB1);
-
- // Zero
- TCCR1A = 0;
- TCCR1B = 0;
-
- // Set stuff
- TCCR1A |= (1 << WGM11) | (1 << COM1A1);
- TCCR1B |= (1 << WGM13) | (1 << WGM12);
- ICR1 = 31249; // Period (TOP)
- OCR1A = 7812; // Duty cycle
- TCCR1B |= (1 << CS12);
-
-}
-
-void loop() {
-
-}
+++ /dev/null
-// Timer 1 - Mode 14
-// f = 2Hz ; δ = 80%
-
-void setup() {
-
- DDRB |= (1 << PB1);
-
- // Zero
- TCCR1A = 0;
- TCCR1B = 0;
-
- // Set stuff
- TCCR1A |= (1 << WGM11) | (1 << COM1A1);
- TCCR1B |= (1 << WGM13) | (1 << WGM12);
- ICR1 = 31249; // Period (TOP)
- OCR1A = 25000; // Duty cycle
- TCCR1B |= (1 << CS12);
-
-}
-
-void loop() {
-
-}
+++ /dev/null
-/*
- * ASCII => Char
- * 0x56 => V
- * 0x0A => [LINE FEED]
- * 0x0D => [CARRIAGE RETURN]
- */
-
-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'); // Sends 0x56
-// Serial.println('V'); // Sends 0x56 0x0D 0x0A
-// Serial.write(0x56); // Sends 0x56
-
- while(Serial.available() > 0)
- {
- Serial.read();
- }
- delay(500);
-}
--- /dev/null
+#define LDR A0
+
+uint16_t value = 0;
+
+void setup()
+{
+ pinMode(A0, INPUT);
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ value = analogRead(LDR);
+ Serial.println(value);
+ delay(100);
+}
--- /dev/null
+/*
+ * ASCII => Char
+ * 0x56 => V
+ * 0x0A => [LINE FEED]
+ * 0x0D => [CARRIAGE RETURN]
+ */
+
+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'); // Sends 0x56
+// Serial.println('V'); // Sends 0x56 0x0D 0x0A
+// Serial.write(0x56); // Sends 0x56
+
+ while(Serial.available() > 0)
+ {
+ Serial.read();
+ }
+ delay(500);
+}
+++ /dev/null
-#define BTN_PIN 2
-#define LED_PIN 13
-
-void button_pressed_ISR(void);
-void slow_computation(void);
-
-volatile uint8_t led_state = 0;
-
-void setup()
-{
- 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);
-}
-
-void loop()
-{
- 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);
- }
-}
-
-void slow_computation(void)
-{
- delay(5000);
-}
+++ /dev/null
-https://www.tinkercad.com/things/b8qUgr1Egv0
--- /dev/null
+#define LED PB5 // LED is connected to digital pin 13
+#define BTN PD2 // Button is connected to digital pin 2
+
+void setup()
+{
+ // PB5 is OUTPUT
+ DDRB |= (1 << PB5); //0b00100000; // 0x20;
+ // PD2 is INPUT
+ DDRD &= ~(1 << BTN);
+ // PD2 PULLUP turn on
+ PORTD |= (1 << BTN);
+
+ cli(); // Disable Global Interrupts
+
+ // Set INT0 mode to FALLING
+ EICRA = 0;
+ EICRA |= (1 << ISC01);
+ // Enable INT0 interrupt
+ EIMSK = 0;
+ EIMSK |= (1 << INT0);
+
+ sei(); // Enable Global Interrupts
+}
+
+void loop()
+{
+ // Empty
+}
+
+ISR(INT0_vect)
+{
+ PORTB ^= (1 << PB5); // Toggle LED
+}
--- /dev/null
+#define LED 12
+#define BTN 2
+
+// Define interrupt flag variable - must be volatile
+//volatile uint8_t state = 1;
+
+void setup() {
+ pinMode(LED,OUTPUT);
+ pinMode(BTN,INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(BTN), ISR_Task, FALLING);
+}
+
+void loop() {
+ /*
+ // Read the interrupt flag and do something
+ if(state == 1)
+ {
+ digitalWrite(LED, !digitalRead(LED));
+ delay(100);
+ state = 0;
+ }
+ */
+}
+
+// Handler for the INT0 external interrupt
+void ISR_Task() {
+ //state = 1; // Better to only set a flag so that the ISR is short and fast
+ //delay(2000); // Show that delay doesn't work
+ digitalWrite(LED, !digitalRead(LED));
+}
--- /dev/null
+#define BTN_PIN 2
+#define LED_PIN 13
+
+void button_pressed_ISR(void);
+void slow_computation(void);
+
+volatile uint8_t led_state = 0;
+
+void setup()
+{
+ 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);
+}
+
+void loop()
+{
+ 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);
+ }
+}
+
+void slow_computation(void)
+{
+ delay(5000);
+}
--- /dev/null
+https://www.tinkercad.com/things/b8qUgr1Egv0
--- /dev/null
+volatile bool change_detected = false;
+
+void setup()
+{
+ // put your setup code here, to run once:
+ DDRC &= ~((1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3));
+ PORTC |= (1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3);
+ PCMSK1 |= (1 << PCINT8) | (1 << PCINT9) | (1 << PCINT10) | (1 << PCINT11);
+ PCICR |= (1 << PCIE1);
+ Serial.begin(38400, SERIAL_8E2);
+}
+
+void loop()
+{
+ if (change_detected)
+ {
+ delay(100);
+ Serial.print("Switch changed: ");
+ Serial.println(PINC & ((1 << PINC0) | (1 << PINC1) | (1 << PINC2) | (1 << PINC3)), BIN);
+ change_detected = false;
+ }
+}
+
+ISR(PCINT1_vect)
+{
+ change_detected = true;
+}
--- /dev/null
+#include <Servo.h>
+
+#define DRV_A1 6
+#define DRV_A2 5
+#define EN_L 7
+#define DRV_A3 9
+#define DRV_A4 11
+#define EN_R 4
+#define SERVO_PIN 10
+
+Servo aservo;
+
+void forward(uint8_t speed);
+void reverse(uint8_t speed);
+void turn_left(uint8_t speed);
+void turn_right(uint8_t speed);
+
+void setup()
+{
+ pinMode(DRV_A1, OUTPUT);
+ pinMode(DRV_A2, OUTPUT);
+ pinMode(EN_L, OUTPUT);
+ digitalWrite(DRV_A1, LOW);
+ digitalWrite(DRV_A2, LOW);
+ digitalWrite(EN_L, HIGH);
+
+ pinMode(DRV_A3, OUTPUT);
+ pinMode(DRV_A4, OUTPUT);
+ pinMode(EN_R, OUTPUT);
+ digitalWrite(DRV_A3, LOW);
+ digitalWrite(DRV_A4, LOW);
+ digitalWrite(EN_R, HIGH);
+
+ aservo.attach(SERVO_PIN);
+}
+
+void loop()
+{
+ /*
+ digitalWrite(DRV_A1, HIGH);
+ analogWrite(DRV_A2, 128);
+ digitalWrite(EN_L, HIGH);
+ */
+
+ //aservo.write(90);
+
+ /*
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ forward(255);
+ delay(5000);
+ turn_right(128);
+ delay(1000);
+ }
+ digitalWrite(EN_L, LOW);
+ digitalWrite(EN_R, LOW);
+ */
+}
+
+void forward(uint8_t speed)
+{
+ analogWrite(DRV_A1, speed);
+ digitalWrite(DRV_A2, LOW);
+ analogWrite(DRV_A3, speed);
+ digitalWrite(DRV_A4, LOW);
+}
+
+void reverse(uint8_t speed)
+{
+ digitalWrite(DRV_A1, LOW);
+ analogWrite(DRV_A2, speed);
+ digitalWrite(DRV_A3, LOW);
+ analogWrite(DRV_A4, speed);
+}
+
+void turn_left(uint8_t speed)
+{
+ digitalWrite(DRV_A1, LOW);
+ analogWrite(DRV_A2, speed);
+ analogWrite(DRV_A3, speed);
+ digitalWrite(DRV_A4, LOW);
+}
+
+void turn_right(uint8_t speed)
+{
+ analogWrite(DRV_A1, speed);
+ digitalWrite(DRV_A2, LOW);
+ digitalWrite(DRV_A3, LOW);
+ analogWrite(DRV_A4, speed);
+}
+
+void stop_motors()
+{
+ digitalWrite(DRV_A1, LOW);
+ digitalWrite(DRV_A2, LOW);
+ digitalWrite(DRV_A3, LOW);
+ digitalWrite(DRV_A4, LOW);
+}
--- /dev/null
+https://www.tinkercad.com/things/8ef4pvh4R76
--- /dev/null
+#define DRV_IN1 11
+#define DRV_IN2 10
+#define DRV_EN 12
+#define POT A0
+
+void setup()
+{
+ pinMode(DRV_IN1, OUTPUT);
+ pinMode(DRV_IN2, OUTPUT);
+ pinMode(DRV_EN, OUTPUT);
+ pinMode(POT, INPUT);
+ digitalWrite(DRV_IN1, LOW);
+ digitalWrite(DRV_IN2, LOW);
+ digitalWrite(DRV_EN, HIGH);
+}
+
+void loop()
+{
+ // Instead of /4, map() or >>2 can be used.
+ analogWrite(DRV_IN1, analogRead(POT) / 4);
+}
--- /dev/null
+https://www.tinkercad.com/things/3tiT8HWMh1X-dcmotorspeedcontrol
--- /dev/null
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\r
+<WORKSPACE>\r
+ <FRAME activewindow="0">\r
+ <PLACEMENT>2c0000000000000001000000ffffffffffffffffffffffffffffffff670000001a000000de06000010040000</PLACEMENT>\r
+ <WINDOW type="default" module="ISIS"/>\r
+ </FRAME>\r
+ <MODULE name="VSMDEBUG">\r
+ <PWI>\r
+ <POPUP w="668" x="166" flags="00008003" y="105" h="210" pid="0" iid="-1">\r
+ <PROPERTIES>\r
+ <ITEM name="Message Column Width">524</ITEM>\r
+ <ITEM name="ShowGrid">No</ITEM>\r
+ <ITEM name="Source Column Width">107</ITEM>\r
+ <ITEM name="Version">100</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="350" x="6" flags="00000032" y="114" h="100" pid="1" iid="-1">\r
+ <PROPERTIES>\r
+ <ITEM name="Address Column Width">87</ITEM>\r
+ <ITEM name="AutoResize">No</ITEM>\r
+ <ITEM name="Gridlines">Yes</ITEM>\r
+ <ITEM name="Name Column Width">87</ITEM>\r
+ <ITEM name="ShowAddresses">Yes</ITEM>\r
+ <ITEM name="ShowPreviousValues">No</ITEM>\r
+ <ITEM name="ShowTypes">No</ITEM>\r
+ <ITEM name="ShowWatchPoint">Yes</ITEM>\r
+ <ITEM name="TriggerMode">0</ITEM>\r
+ <ITEM name="Value Column Width">87</ITEM>\r
+ <ITEM name="Version">100</ITEM>\r
+ <ITEM name="Watch Expression Column Width">87</ITEM>\r
+ <ITEM name="nItems">0</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="226" x="6" flags="00000008" y="114" h="215" pid="3" iid="1">\r
+ <PROPERTIES/>\r
+ </POPUP>\r
+ <POPUP w="1" x="6" flags="0000000a" y="114" h="1" pid="10" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000000</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="1" x="6" flags="0000000a" y="114" h="2" pid="6" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000000</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="1" x="6" flags="0000000a" y="114" h="2" pid="7" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000000</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="16" x="159" flags="00000000" y="285" h="32" pid="14" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000000</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="1" x="6" flags="0000000a" y="114" h="2" pid="4" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000100</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="1" x="6" flags="0000000a" y="114" h="1" pid="13" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="DataType">2</ITEM>\r
+ <ITEM name="DispChars">Yes</ITEM>\r
+ <ITEM name="DispFormat">2</ITEM>\r
+ <ITEM name="ShowChanges">Yes</ITEM>\r
+ <ITEM name="ShowToolTips">Yes</ITEM>\r
+ <ITEM name="TopLineAddress">00000020</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="944" x="7" flags="0000002b" y="135" h="724" pid="1" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="CaseSensitive">No</ITEM>\r
+ <ITEM name="DISPADDRS">Yes</ITEM>\r
+ <ITEM name="DISPLNUMS">No</ITEM>\r
+ <ITEM name="DISPOPCODES">No</ITEM>\r
+ <ITEM name="FIXUPBPTS">Yes</ITEM>\r
+ <ITEM name="WordsOnly">No</ITEM>\r
+ <ITEM name="nBreakpoints">0</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ <POPUP w="1910" x="6" flags="0000000b" y="899" h="121" pid="2" iid="1">\r
+ <PROPERTIES>\r
+ <ITEM name="Address Column Width">636</ITEM>\r
+ <ITEM name="AutoResize">No</ITEM>\r
+ <ITEM name="Gridlines">Yes</ITEM>\r
+ <ITEM name="Name Column Width">636</ITEM>\r
+ <ITEM name="ShowAddresses">Yes</ITEM>\r
+ <ITEM name="ShowGlobals">Yes</ITEM>\r
+ <ITEM name="ShowPreviousValues">No</ITEM>\r
+ <ITEM name="ShowTypes">No</ITEM>\r
+ <ITEM name="ShowWatchPoint">No</ITEM>\r
+ <ITEM name="TriggerMode">0</ITEM>\r
+ <ITEM name="Value Column Width">636</ITEM>\r
+ <ITEM name="Version">100</ITEM>\r
+ <ITEM name="nItems">0</ITEM>\r
+ </PROPERTIES>\r
+ </POPUP>\r
+ </PWI>\r
+ </MODULE>\r
+</WORKSPACE>\r
--- /dev/null
+#include <inttypes.h>
+
+#define A1_PIN 9
+#define A2_PIN 8
+#define B1_PIN 11
+#define B2_PIN 10
+#define EN_PIN 12
+
+#define STEP_TIME 1000 // ms
+
+//#define FULL_STEP
+#define HALF_STEP
+
+#ifdef FULL_STEP
+#define NUM_STEPS 4
+const uint8_t coil_current[NUM_STEPS][4] =
+{
+ {1, 0, 0, 1},
+ {1, 1, 0, 0},
+ {0, 1, 1, 0},
+ {0, 0, 1, 1}
+};
+#endif
+
+#ifdef HALF_STEP
+#define NUM_STEPS 8
+const uint8_t coil_current[NUM_STEPS][4] =
+{
+ {1, 0, 0, 1},
+ {1, 0, 0, 0},
+ {1, 1, 0, 0},
+ {0, 1, 0, 0},
+ {0, 1, 1, 0},
+ {0, 0, 1, 0},
+ {0, 0, 1, 1},
+ {0, 0, 0, 1}
+};
+#endif
+
+const uint8_t stepper_pins[4] = {A2_PIN, A1_PIN, B1_PIN, B2_PIN};
+
+void setup()
+{
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ pinMode(stepper_pins[i], OUTPUT);
+ }
+ pinMode(EN_PIN, OUTPUT);
+ digitalWrite(EN_PIN, HIGH);
+}
+
+void loop()
+{
+ static uint8_t step = 0;
+
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ digitalWrite(stepper_pins[i], coil_current[step][i]);
+ }
+
+ step++;
+ if (step >= NUM_STEPS)
+ {
+ step = 0;
+ }
+
+ delay(STEP_TIME);
+}\r
--- /dev/null
+#include <inttypes.h>
+
+#define A1_PIN 9
+#define A2_PIN 8
+#define B1_PIN 11
+#define B2_PIN 10
+#define EN_PIN 12
+
+#define STEP_TIME 200 // ms, max 1000
+
+#define FULL_STEP
+//#define HALF_STEP
+
+#ifdef FULL_STEP
+#define NUM_STEPS 4
+const uint8_t coil_current[NUM_STEPS][4] =
+{
+ {1, 0, 0, 1},
+ {1, 1, 0, 0},
+ {0, 1, 1, 0},
+ {0, 0, 1, 1}
+};
+#endif
+
+#ifdef HALF_STEP
+#define NUM_STEPS 8
+const uint8_t coil_current[NUM_STEPS][4] =
+{
+ {1, 0, 0, 1},
+ {1, 0, 0, 0},
+ {1, 1, 0, 0},
+ {0, 1, 0, 0},
+ {0, 1, 1, 0},
+ {0, 0, 1, 0},
+ {0, 0, 1, 1},
+ {0, 0, 0, 1}
+};
+#endif
+
+void timer1_init(void);
+void stepper_init(void);
+
+const uint8_t stepper_pins[4] = {A2_PIN, A1_PIN, B1_PIN, B2_PIN};
+
+void setup()
+{
+ stepper_init();
+ timer1_init();
+}
+
+void loop()
+{}
+
+void timer1_init(void)
+{
+ // Disable interrupts during timer configuration
+ noInterrupts();
+ // Select CTC mode (4) and set the prescaler to divide the clock by 256
+ // resulting in timer frequency of 62.5 kHz
+ TCCR1A = 0;
+ TCCR1B = (1 << WGM12) | (1 << CS12);
+ // Enable interrupt when reaching the maximum value (OCR1A)
+ TIMSK1 = (1 << OCIE1A);
+ // Set the timer period to 50 ms (50 * 62.5 = 3125)
+ OCR1A = (int) STEP_TIME * 62.5;
+ // Reset OC register B and the input capture register. They are not used
+ ICR1 = OCR1B = 0;
+ // Reset the counter register
+ TCNT1 = 0;
+ // Enable inerrupts
+ interrupts();
+}
+
+ISR(TIMER1_COMPA_vect)
+{
+ static volatile uint8_t step = 0;
+
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ digitalWrite(stepper_pins[i], coil_current[step][i]);
+ }
+
+ step++;
+ if (step >= NUM_STEPS)
+ {
+ step = 0;
+ }
+}
+
+void stepper_init(void)
+{
+ for (uint8_t i = 0; i < 4; i++)
+ {
+ pinMode(stepper_pins[i], OUTPUT);
+ }
+ pinMode(EN_PIN, OUTPUT);
+ digitalWrite(EN_PIN, HIGH);
+}
+\r
--- /dev/null
+#include <Adafruit_NeoPixel.h>
+
+#define LED_STRIP_PIN 12
+#define SWITCH_PIN 2
+
+#define IN1 5
+#define IN2 6
+#define EN 13
+#define POT A3
+
+#define NUM_PIXELS 10
+
+void button_pressed_ISR(void);
+
+volatile uint8_t pixel_color = 0;
+volatile uint16_t counter = 0;
+Adafruit_NeoPixel led_strip(NUM_PIXELS, LED_STRIP_PIN, NEO_GRB);
+
+void setup()
+{
+ pinMode(SWITCH_PIN, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(SWITCH_PIN), button_pressed_ISR, FALLING);
+ pinMode(LED_STRIP_PIN, OUTPUT);
+ led_strip.begin();
+
+ pinMode(IN1, OUTPUT);
+ pinMode(IN2, OUTPUT);
+ digitalWrite(IN2, LOW);
+ pinMode(EN, OUTPUT);
+ digitalWrite(EN, HIGH);
+ pinMode(POT, INPUT);
+
+ noInterrupts();
+
+ TCNT1 = 0;
+
+ ICR1 = 311;
+ OCR1B = 194;
+ TIMSK1 = (1 << TOIE1);
+ TCCR1A = (1 << WGM11) | (1 << COM1B1);
+ TCCR1B = (1 << WGM12) | (1 << WGM13) | (1 << CS12);
+
+ interrupts();
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ if (pixel_color)
+ {
+ led_strip.setPixelColor(3, led_strip.Color(0, 255, 0));
+ }
+ else
+ {
+ led_strip.setPixelColor(3, led_strip.Color(255, 255, 255));
+ }
+ led_strip.show();
+ delay(100);
+
+ analogWrite(IN1, map(analogRead(POT), 0, 1023, 0, 255));
+}
+
+void button_pressed_ISR(void)
+{
+ pixel_color = !pixel_color;
+}
+
+ISR(TIMER1_OVF_vect)
+{
+ counter++;
+}
--- /dev/null
+https://www.tinkercad.com/things/ffni7S7fML6
+++ /dev/null
-volatile bool change_detected = false;
-
-void setup()
-{
- // put your setup code here, to run once:
- DDRC &= ~((1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3));
- PORTC |= (1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3);
- PCMSK1 |= (1 << PCINT8) | (1 << PCINT9) | (1 << PCINT10) | (1 << PCINT11);
- PCICR |= (1 << PCIE1);
- Serial.begin(38400, SERIAL_8E2);
-}
-
-void loop()
-{
- if (change_detected)
- {
- delay(100);
- Serial.print("Switch changed: ");
- Serial.println(PINC & ((1 << PINC0) | (1 << PINC1) | (1 << PINC2) | (1 << PINC3)), BIN);
- change_detected = false;
- }
-}
-
-ISR(PCINT1_vect)
-{
- change_detected = true;
-}
--- /dev/null
+/*
+ Timer 1 is set to generate Compare Match Interrupt with frequency 1Hz
+ The counter counts with frequency 16MHz/1024 = 15.625kHz
+ For 1s the counter will reach value of [15.625kHz*1s - 1] = [15625 - 1] = 15624
+ This value is set as compare value so that when counter reaches it
+ it will generate Interrupt with Period exactly 1s => Frequency 1Hz
+ LED attached on pin 13 is TOGGLED with this frequency of 1Hz so it stays 1s on and 1s off
+*/
+
+volatile boolean toggle = 0;
+
+void setup() {
+ pinMode(13, OUTPUT); // Set pin 13 as output
+ noInterrupts(); //cli(); // Stop reception of interrupts
+
+ // Set Timer 1 Control registers and counter to 0
+ TCCR1A = 0;
+ TCCR1B = 0;
+ TIMSK1 = 0;
+ TCNT1 = 0;
+
+ // Set compare match value = Fclk_io / (Fout * Prescaler) - 1
+ OCR1A = 15624; // = (16MHz) / (1 * 1024) - 1
+ TIMSK1 |= (1 << OCIE1A); // Enable compare match interrupt
+
+ // Set Timer 1 Mode of operation to Clear Timer on Compare Match (CTC -> Mode 4)
+ TCCR1B |= (1 << WGM12); // Mode 4
+
+ // Set Timer 1 Clock prescaler and source so that the timer starts counting
+ TCCR1B |= (1 << CS12) | (1 << CS10); // Set prescaler to 1024 (=> enable the clock)
+
+ interrupts(); //sei(); // Allow reception of interrupts
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+}
+
+/*
+ Timer1 Interrupt Service Routine (ISR)
+ Toggle pin 13 (LED) every 1s
+ Generates pulse wave of frequency 1Hz/2 = 0.5Hz
+ Takes two cycles for full wave - toggle high then after 1s toggle low after 1s repeat
+*/
+ISR(TIMER1_COMPA_vect) {
+ if (toggle == 1) {
+ digitalWrite(13, HIGH);
+ toggle = 0;
+ }
+ else {
+ digitalWrite(13, LOW);
+ toggle = 1;
+ }
+}
--- /dev/null
+void setup() {
+ // Set pin 13 to output
+ pinMode(13, OUTPUT);
+
+ // Stop reception of interrupts
+ noInterrupts(); //cli();
+
+ // Set PB1 to be an output (Pin-9 Arduino UNO)
+ DDRB |= (1 << PB1);
+
+ // Clear Timer/Counter Control Registers
+ TCCR1A = 0;
+ TCCR1B = 0;
+ TIMSK1 = 0;
+
+ // Set non-inverting mode - Table 15-3 (page 108)
+ TCCR1A |= (1 << COM1A1);
+ TCCR1A |= (1 << COM1B1);
+
+ // Set Fast-PWM Mode (Mode 14) - Table 15-5 (page 109)
+ TCCR1A |= (1 << WGM11);
+ TCCR1B |= (1 << WGM12);
+ TCCR1B |= (1 << WGM13);
+
+ // Clear Timer 1 Counter
+ TCNT1 = 0;
+
+ // Set PWM frequency/top value - Output PWM 10kHz
+ ICR1 = 199; // Fclk_io / (Fout * Prescaler) - 1
+ OCR1A = 100; // Output OC1A will be ON for [OCR1A/(ICR1+1)]% of the time -> 100/(199+1) = 50%
+ OCR1B = 50;
+
+ // Enable compare match interrupt
+ TIMSK1 |= (1 << OCIE1A);
+ TIMSK1 |= (1 << OCIE1B);
+ TIMSK1 |= (1 << TOIE1);
+
+ // Set prescaler to 8 and starts PWM
+ TCCR1B |= (1 << CS11);
+
+ // Enables interrupts
+ interrupts(); //sei();
+}
+
+void loop() {
+ // Empty
+}
+
+//Timer1 Compare Match Interrupt turns OFF pin 13 (LED)
+ISR(TIMER1_COMPA_vect) {
+ digitalWrite(13, LOW);
+}
+
+//Timer1 Compare Match Interrupt turns OFF pin 13 (LED)
+ISR(TIMER1_COMPB_vect) {
+ //digitalWrite(13, LOW);
+}
+
+//Timer1 Overflow Interrupt turns ON pin 13 (LED)
+ISR(TIMER1_OVF_vect) {
+ digitalWrite(13, HIGH);
+}
--- /dev/null
+https://www.tinkercad.com/things/c8JLkjplQKy
--- /dev/null
+volatile uint16_t var = 0;
+
+void setup()
+{
+ noInterrupts(); // Забраняваме глобално прекъсванията //cli();
+
+ // Зануляване на конфигурацията
+ TCCR1A = 0;
+ TCCR1B = 0;
+ TCCR1C = 0;
+ TCNT1 = 0;
+ OCR1A = 0;
+ OCR1B = 0;
+ ICR1 = 0;
+ TIMSK1 = 0;
+ TIFR1 = 0;
+
+ // Режим на таймера - 14 Fast-PWM
+ TCCR1A = TCCR1A | (1 << WGM11);
+ TCCR1B = TCCR1B | (1 << WGM12);
+ TCCR1B = TCCR1B | (1 << WGM13);
+ // TCCR1A |= (1 << WGM11);
+ // TCCR1B = TCCR1B | (1 << WGM12) | (1 << WGM13);
+
+ // Режим на изводите - неинв.
+ TCCR1A = TCCR1A | (1 << COM1A1) | (1 << COM1B1);
+
+ // Честота - 500Hz
+ // Избираме Prescaler = 1
+ ICR1 = 31999; // TOP = 16MHZ/(1*500Hz)-1 = 31999
+
+ // Коеф. на запълване - 75%
+ OCR1A = 23999; // DUTY = TOP * 75% = 31999*75% = 23999
+
+ // Прекъсване - CM A
+ TIMSK1 |= (1 << OCIE1A);
+
+ // Пускане на таймера
+ TCCR1B |= (1 << CS10);
+
+ interrupts(); // Разрешаваме глобално прекъсванията //sei();
+}
+
+ISR(TIMER1_COMPA_vect)
+{
+ var++;
+}
+
+void loop()
+{
+
+}
--- /dev/null
+#define BTN_PIN 2
+
+volatile uint8_t timer_en = 0;
+
+void button_pressed_ISR(void);
+
+void setup()
+{
+ // Stop reception of interrupts
+ noInterrupts(); //cli();
+
+ pinMode(BTN_PIN, INPUT_PULLUP);
+ attachInterrupt(digitalPinToInterrupt(BTN_PIN), button_pressed_ISR, FALLING);
+
+ // Set PB1 to be an output (Pin9 Arduino UNO)
+ DDRB |= (1 << PB1);
+
+ // Clear Timer/Counter Control Registers
+ TCCR1A = 0;
+ TCCR1B = 0;
+ TIMSK1 = 0;
+
+ // Set non-inverting mode - Table 15-3 (page 108)
+ TCCR1A |= (1 << COM1A1);
+
+ // Set Fast-PWM Mode (Mode 14) - Table 15-5 (page 109)
+ TCCR1A |= (1 << WGM11);
+ TCCR1B |= (1 << WGM12);
+ TCCR1B |= (1 << WGM13);
+
+ // Clear Timer 1 Counter
+ TCNT1 = 0;
+
+ // Set PWM frequency/top value - Output PWM 1Hz
+ ICR1 = 15625;
+ OCR1A = 10000;
+
+ // Enable interrupts
+ interrupts();
+}
+
+void loop() {
+ // some useless code here
+ }
+
+void button_pressed_ISR(void)
+{
+ if (timer_en)
+ {
+ timer_en = 0;
+ // Disable the timer by selecting "none" as the clock source
+ TCCR1B &= ~((1 << CS11) | (1 << CS12) | (1 << CS10));
+ }
+ else
+ {
+ timer_en = 1;
+ // Enable the timer
+ TCCR1B |= (1 << CS12) | (1 << CS10);
+ TCCR1B &= ~(1 << CS11);
+ }
+}
--- /dev/null
+https://www.tinkercad.com/things/abCdiMvkJs6
--- /dev/null
+#define DIP_SW_0 8
+#define DIP_SW_1 9
+#define DIP_SW_2 10
+#define DIP_SW_3 11
+
+#define BUTTON 2
+#define LED 13
+
+void button_ISR(void);
+
+volatile bool led_flag = false;
+
+void setup()
+{
+ pinMode(DIP_SW_0, INPUT_PULLUP);
+ pinMode(DIP_SW_1, INPUT_PULLUP);
+ pinMode(DIP_SW_2, INPUT_PULLUP);
+ pinMode(DIP_SW_3, INPUT_PULLUP);
+ pinMode(BUTTON, INPUT_PULLUP);
+ pinMode(LED, OUTPUT);
+ digitalWrite(LED, LOW);
+
+ attachInterrupt(digitalPinToInterrupt(BUTTON), button_ISR, FALLING);
+
+ // Disable interrupts during timer configuration
+ cli();
+
+ // Zero the control and counter registers
+ TCCR1A = TCCR1B = TIMSK1 = 0;
+ TCNT1 = 0;
+
+ // Select mode 15 (Fast PWM, TOP = OCR1A)
+ TCCR1A |= (1 << WGM10);
+ TCCR1A |= (1 << WGM11);
+ TCCR1B |= (1 << WGM12);
+ TCCR1B |= (1 << WGM13);
+
+ // Set max counter value (frequency)
+ OCR1A = 7811;
+
+ // Enable timer overflow interrupt
+ TIMSK1 |= (1 << TOIE1);
+
+ // Set prescaler to 1024
+ TCCR1B |= (1 << CS10) | (1 << CS12);
+
+ // Enable interrupts
+ sei();
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ Serial.println(OCR1A);
+ delay(1000);
+}
+
+ISR(TIMER1_OVF_vect)
+{
+ digitalWrite(LED, led_flag);
+ led_flag = !led_flag;
+}
+
+void button_ISR(void)
+{
+ uint8_t f = ~PINB & 0x0F;
+
+ if (f)
+ {
+ OCR1A = 16000000 / (1024 * f) - 1;
+ }
+}
--- /dev/null
+ https://www.tinkercad.com/things/2g5g32R3Fb7
--- /dev/null
+// Timer 1 - Mode 14
+// f = 10kHz ; δ = 25%
+
+void setup() {
+
+ DDRB |= (1 << PB1);
+
+ // Zero
+ TCCR1A = 0;
+ TCCR1B = 0;
+
+ // Set stuff
+ TCCR1A |= (1 << WGM11) | (1 << COM1A1);
+ TCCR1B |= (1 << WGM13) | (1 << WGM12);
+ ICR1 = 1599; // Period (TOP)
+ OCR1A = 400; // Duty cycle
+ TCCR1B |= (1 << CS10);
+
+}
+
+void loop() {
+
+}
--- /dev/null
+// Timer 1 - Mode 14
+// f = 10kHz ; δ = 50%
+
+void setup() {
+
+ DDRB |= (1 << PB1);
+
+ // Zero
+ TCCR1A = 0;
+ TCCR1B = 0;
+
+ // Set stuff
+ TCCR1A |= (1 << WGM11) | (1 << COM1A1);
+ TCCR1B |= (1 << WGM13) | (1 << WGM12);
+ ICR1 = 1599; // Period (TOP)
+ OCR1A = 800; // Duty cycle
+ TCCR1B |= (1 << CS10);
+
+}
+
+void loop() {
+
+}
--- /dev/null
+// Timer 1 - Mode 14
+// f = 2Hz ; δ = 25%
+
+void setup() {
+
+ DDRB |= (1 << PB1);
+
+ // Zero
+ TCCR1A = 0;
+ TCCR1B = 0;
+
+ // Set stuff
+ TCCR1A |= (1 << WGM11) | (1 << COM1A1);
+ TCCR1B |= (1 << WGM13) | (1 << WGM12);
+ ICR1 = 31249; // Period (TOP)
+ OCR1A = 7812; // Duty cycle
+ TCCR1B |= (1 << CS12);
+
+}
+
+void loop() {
+
+}
--- /dev/null
+// Timer 1 - Mode 14
+// f = 2Hz ; δ = 80%
+
+void setup() {
+
+ DDRB |= (1 << PB1);
+
+ // Zero
+ TCCR1A = 0;
+ TCCR1B = 0;
+
+ // Set stuff
+ TCCR1A |= (1 << WGM11) | (1 << COM1A1);
+ TCCR1B |= (1 << WGM13) | (1 << WGM12);
+ ICR1 = 31249; // Period (TOP)
+ OCR1A = 25000; // Duty cycle
+ TCCR1B |= (1 << CS12);
+
+}
+
+void loop() {
+
+}