From: Vladimir Garistov Date: Mon, 7 Nov 2022 01:03:58 +0000 (+0200) Subject: Ordered the examples X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=113ebd89d1c50b0cb79e95803dddc398f1985ade;p=vmks.git Ordered the examples --- diff --git a/Examples/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png b/Examples/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png deleted file mode 100644 index 472ae2b..0000000 Binary files a/Examples/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png and /dev/null differ diff --git a/Examples/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino b/Examples/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino deleted file mode 100644 index e265976..0000000 --- a/Examples/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino +++ /dev/null @@ -1,85 +0,0 @@ -#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); - } - } -} diff --git a/Examples/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt b/Examples/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt deleted file mode 100644 index 25a297f..0000000 --- a/Examples/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/bJ9mxNp3wXG diff --git a/Examples/7-segm_bidirectional_counter/7-segm_bidirectional_counter.ino b/Examples/7-segm_bidirectional_counter/7-segm_bidirectional_counter.ino deleted file mode 100644 index 058a909..0000000 --- a/Examples/7-segm_bidirectional_counter/7-segm_bidirectional_counter.ino +++ /dev/null @@ -1,137 +0,0 @@ -#include - -#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--; -} diff --git a/Examples/7-segm_bidirectional_counter/7-segm_bidirectional_counter.png b/Examples/7-segm_bidirectional_counter/7-segm_bidirectional_counter.png deleted file mode 100644 index 8aa9918..0000000 Binary files a/Examples/7-segm_bidirectional_counter/7-segm_bidirectional_counter.png and /dev/null differ diff --git a/Examples/7-segm_bidirectional_counter/tinkercad_link.txt b/Examples/7-segm_bidirectional_counter/tinkercad_link.txt deleted file mode 100644 index 03bf407..0000000 --- a/Examples/7-segm_bidirectional_counter/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/kQ6afgEqekR diff --git a/Examples/7-segm_byte_display/7-segm_byte_display.ino b/Examples/7-segm_byte_display/7-segm_byte_display.ino deleted file mode 100644 index 5b55605..0000000 --- a/Examples/7-segm_byte_display/7-segm_byte_display.ino +++ /dev/null @@ -1,133 +0,0 @@ -#include - -#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); -} diff --git a/Examples/7-segm_byte_display/7-segm_byte_display.png b/Examples/7-segm_byte_display/7-segm_byte_display.png deleted file mode 100644 index 69c7efe..0000000 Binary files a/Examples/7-segm_byte_display/7-segm_byte_display.png and /dev/null differ diff --git a/Examples/7-segm_byte_display/tinkercad_link.txt b/Examples/7-segm_byte_display/tinkercad_link.txt deleted file mode 100644 index b34ead0..0000000 --- a/Examples/7-segm_byte_display/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/aHW3wNDugHU diff --git a/Examples/7-segm_driver/7-segm_driver.ino b/Examples/7-segm_driver/7-segm_driver.ino deleted file mode 100644 index bbff548..0000000 --- a/Examples/7-segm_driver/7-segm_driver.ino +++ /dev/null @@ -1,67 +0,0 @@ -#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); -} diff --git a/Examples/7-segm_driver/7-segm_driver.png b/Examples/7-segm_driver/7-segm_driver.png deleted file mode 100644 index e543614..0000000 Binary files a/Examples/7-segm_driver/7-segm_driver.png and /dev/null differ diff --git a/Examples/7-segm_driver/tinkercad_link.txt b/Examples/7-segm_driver/tinkercad_link.txt deleted file mode 100644 index db5e83d..0000000 --- a/Examples/7-segm_driver/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/kaVhIKUgeAY diff --git a/Examples/7-segm_driver_random/7-segm_driver_random.ino b/Examples/7-segm_driver_random/7-segm_driver_random.ino deleted file mode 100644 index 075efc3..0000000 --- a/Examples/7-segm_driver_random/7-segm_driver_random.ino +++ /dev/null @@ -1,85 +0,0 @@ -#include - -#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); - } -} diff --git a/Examples/7-segm_driver_random/7-segm_driver_random.png b/Examples/7-segm_driver_random/7-segm_driver_random.png deleted file mode 100644 index e23e584..0000000 Binary files a/Examples/7-segm_driver_random/7-segm_driver_random.png and /dev/null differ diff --git a/Examples/7-segm_driver_random/tinkercad_link.txt b/Examples/7-segm_driver_random/tinkercad_link.txt deleted file mode 100644 index 2d132b6..0000000 --- a/Examples/7-segm_driver_random/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/3GNvrtWwhQc diff --git a/Examples/7-segm_raw/7-segm_raw.ino b/Examples/7-segm_raw/7-segm_raw.ino deleted file mode 100644 index a0d0057..0000000 --- a/Examples/7-segm_raw/7-segm_raw.ino +++ /dev/null @@ -1,66 +0,0 @@ -#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; -} diff --git a/Examples/7-segm_raw/7-segm_raw.png b/Examples/7-segm_raw/7-segm_raw.png deleted file mode 100644 index 65c056b..0000000 Binary files a/Examples/7-segm_raw/7-segm_raw.png and /dev/null differ diff --git a/Examples/7-segm_raw/tinkercad_link.txt b/Examples/7-segm_raw/tinkercad_link.txt deleted file mode 100644 index 2e99b79..0000000 --- a/Examples/7-segm_raw/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/a091SYpyBV8 diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino deleted file mode 100644 index 8cb03d0..0000000 --- a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.ino +++ /dev/null @@ -1,124 +0,0 @@ -#include - -#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 EN2_PIN 3 -#define EN3_PIN 2 - -#define DIGITS 4 - -int print_dec(uint16_t value); -int print_digit(uint8_t position, uint8_t digit); -void emulate_timer_ISR(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, EN2_PIN, EN3_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); - } -} - -void loop() -{ - for (uint16_t cnt = (int) pow(10, DIGITS) - 1; cnt > 0; cnt--) - { - print_dec(cnt); - - // This is garbage, don't use it! - for(uint8_t i = 0; i < 10; i++) - { - delay(10); - emulate_timer_ISR(); - } - } - delay(3000); -} - -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 || 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); -} diff --git a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.png b/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.png deleted file mode 100644 index fee62bb..0000000 Binary files a/Examples/7-segm_raw_dynamic/7-segm_raw_dynamic.png and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic/tinkercad_link.txt b/Examples/7-segm_raw_dynamic/tinkercad_link.txt deleted file mode 100644 index c24692b..0000000 --- a/Examples/7-segm_raw_dynamic/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/7eGYywVu5PG diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF deleted file mode 100644 index dd885da..0000000 Binary files a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino deleted file mode 100644 index 35414d5..0000000 --- a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino +++ /dev/null @@ -1,144 +0,0 @@ -#include - -#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 EN2_PIN 3 -#define EN3_PIN 2 - -#define DIGITS 4 - -int print_dec(uint16_t value); -int print_digit(uint8_t position, uint8_t digit); -void timer_init(void); -void gpio_init(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, EN2_PIN, EN3_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() -{ - gpio_init(); - timer_init(); -} - -void loop() -{ - for (uint16_t cnt = (int) pow(10, DIGITS) - 1; cnt > 0; cnt--) - { - print_dec(cnt); - delay(100); - } - delay(3000); -} - -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 || digit > 15) - { - return -1; - } - - display_value[position] = digit; - - return 0; -} - -ISR(TIMER1_OVF_vect) -{ - 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 gpio_init(void) -{ - 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); - } -} - -void timer_init(void) -{ - noInterrupts(); - - // After clearing TCCR1B the timer is stopped - TCCR1B = 0; - TCNT1 = 0; - - TCCR1A = (1 << WGM11); - TCCR1B |= (1 << WGM12) | (1 << WGM13); - TIMSK1 = (1 << TOIE1); - - // Set frequency to 1kHz - ICR1 = 1999; - TCCR1B |= (1 << CS11); - - interrupts(); -} diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.standard.hex b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.standard.hex deleted file mode 100644 index ea3e572..0000000 --- a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.standard.hex +++ /dev/null @@ -1,93 +0,0 @@ -: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 diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.with_bootloader.standard.hex b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.with_bootloader.standard.hex deleted file mode 100644 index 443d475..0000000 --- a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.with_bootloader.standard.hex +++ /dev/null @@ -1,127 +0,0 @@ -: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 diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj deleted file mode 100644 index 8eb8c65..0000000 Binary files a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace deleted file mode 100644 index 1c21abc..0000000 --- a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace +++ /dev/null @@ -1,101 +0,0 @@ - - - - 2c0000000200000003000000ffffffffffffffffffffffffffffffffab0000000d000000d606000004040000 - - - - - - - - 542 - No - 100 - 120 - 100 - - - - - 83 - No - Yes - 83 - Yes - No - No - Yes - 0 - 83 - 100 - 83 - 0 - - - - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000100 - - - - - 2 - Yes - 2 - Yes - Yes - 00000020 - - - - - diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.VANKATA-513.ivans.workspace b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.VANKATA-513.ivans.workspace deleted file mode 100644 index 5545e77..0000000 --- a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.VANKATA-513.ivans.workspace +++ /dev/null @@ -1,100 +0,0 @@ - - - - 2c00000002000000030000000083ffff0083ffffffffffffffffffffb20000000c000000ce060000fa030000 - - - - - - - 142 - No - 100 - 120 - 100 - - - - - 83 - No - Yes - 83 - Yes - No - No - Yes - 0 - 83 - 100 - 83 - 0 - - - - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000100 - - - - - 2 - Yes - 2 - Yes - Yes - 00000020 - - - - - diff --git a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png b/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png deleted file mode 100644 index 26fb620..0000000 Binary files a/Examples/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak b/Examples/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak deleted file mode 100644 index 9bed130..0000000 Binary files a/Examples/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak and /dev/null differ diff --git a/Examples/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak b/Examples/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak deleted file mode 100644 index d482f6c..0000000 Binary files a/Examples/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak and /dev/null differ diff --git a/Examples/7-segm_shield/7-segm_shield.ino b/Examples/7-segm_shield/7-segm_shield.ino deleted file mode 100644 index fbd78c6..0000000 --- a/Examples/7-segm_shield/7-segm_shield.ino +++ /dev/null @@ -1,44 +0,0 @@ -#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; -} diff --git a/Examples/7-segment/7-segm_bidirectional_counter/7-segm_bidirectional_counter.ino b/Examples/7-segment/7-segm_bidirectional_counter/7-segm_bidirectional_counter.ino new file mode 100644 index 0000000..058a909 --- /dev/null +++ b/Examples/7-segment/7-segm_bidirectional_counter/7-segm_bidirectional_counter.ino @@ -0,0 +1,137 @@ +#include + +#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--; +} diff --git a/Examples/7-segment/7-segm_bidirectional_counter/7-segm_bidirectional_counter.png b/Examples/7-segment/7-segm_bidirectional_counter/7-segm_bidirectional_counter.png new file mode 100644 index 0000000..8aa9918 Binary files /dev/null and b/Examples/7-segment/7-segm_bidirectional_counter/7-segm_bidirectional_counter.png differ diff --git a/Examples/7-segment/7-segm_bidirectional_counter/tinkercad_link.txt b/Examples/7-segment/7-segm_bidirectional_counter/tinkercad_link.txt new file mode 100644 index 0000000..03bf407 --- /dev/null +++ b/Examples/7-segment/7-segm_bidirectional_counter/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/kQ6afgEqekR diff --git a/Examples/7-segment/7-segm_byte_display/7-segm_byte_display.ino b/Examples/7-segment/7-segm_byte_display/7-segm_byte_display.ino new file mode 100644 index 0000000..5b55605 --- /dev/null +++ b/Examples/7-segment/7-segm_byte_display/7-segm_byte_display.ino @@ -0,0 +1,133 @@ +#include + +#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); +} diff --git a/Examples/7-segment/7-segm_byte_display/7-segm_byte_display.png b/Examples/7-segment/7-segm_byte_display/7-segm_byte_display.png new file mode 100644 index 0000000..69c7efe Binary files /dev/null and b/Examples/7-segment/7-segm_byte_display/7-segm_byte_display.png differ diff --git a/Examples/7-segment/7-segm_byte_display/tinkercad_link.txt b/Examples/7-segment/7-segm_byte_display/tinkercad_link.txt new file mode 100644 index 0000000..b34ead0 --- /dev/null +++ b/Examples/7-segment/7-segm_byte_display/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/aHW3wNDugHU diff --git a/Examples/7-segment/7-segm_driver/7-segm_driver.ino b/Examples/7-segment/7-segm_driver/7-segm_driver.ino new file mode 100644 index 0000000..bbff548 --- /dev/null +++ b/Examples/7-segment/7-segm_driver/7-segm_driver.ino @@ -0,0 +1,67 @@ +#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); +} diff --git a/Examples/7-segment/7-segm_driver/7-segm_driver.png b/Examples/7-segment/7-segm_driver/7-segm_driver.png new file mode 100644 index 0000000..e543614 Binary files /dev/null and b/Examples/7-segment/7-segm_driver/7-segm_driver.png differ diff --git a/Examples/7-segment/7-segm_driver/tinkercad_link.txt b/Examples/7-segment/7-segm_driver/tinkercad_link.txt new file mode 100644 index 0000000..db5e83d --- /dev/null +++ b/Examples/7-segment/7-segm_driver/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/kaVhIKUgeAY diff --git a/Examples/7-segment/7-segm_driver_random/7-segm_driver_random.ino b/Examples/7-segment/7-segm_driver_random/7-segm_driver_random.ino new file mode 100644 index 0000000..075efc3 --- /dev/null +++ b/Examples/7-segment/7-segm_driver_random/7-segm_driver_random.ino @@ -0,0 +1,85 @@ +#include + +#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); + } +} diff --git a/Examples/7-segment/7-segm_driver_random/7-segm_driver_random.png b/Examples/7-segment/7-segm_driver_random/7-segm_driver_random.png new file mode 100644 index 0000000..e23e584 Binary files /dev/null and b/Examples/7-segment/7-segm_driver_random/7-segm_driver_random.png differ diff --git a/Examples/7-segment/7-segm_driver_random/tinkercad_link.txt b/Examples/7-segment/7-segm_driver_random/tinkercad_link.txt new file mode 100644 index 0000000..2d132b6 --- /dev/null +++ b/Examples/7-segment/7-segm_driver_random/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/3GNvrtWwhQc diff --git a/Examples/7-segment/7-segm_raw/7-segm_raw.ino b/Examples/7-segment/7-segm_raw/7-segm_raw.ino new file mode 100644 index 0000000..a0d0057 --- /dev/null +++ b/Examples/7-segment/7-segm_raw/7-segm_raw.ino @@ -0,0 +1,66 @@ +#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; +} diff --git a/Examples/7-segment/7-segm_raw/7-segm_raw.png b/Examples/7-segment/7-segm_raw/7-segm_raw.png new file mode 100644 index 0000000..65c056b Binary files /dev/null and b/Examples/7-segment/7-segm_raw/7-segm_raw.png differ diff --git a/Examples/7-segment/7-segm_raw/tinkercad_link.txt b/Examples/7-segment/7-segm_raw/tinkercad_link.txt new file mode 100644 index 0000000..2e99b79 --- /dev/null +++ b/Examples/7-segment/7-segm_raw/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/a091SYpyBV8 diff --git a/Examples/7-segment/7-segm_raw_dynamic/7-segm_raw_dynamic.ino b/Examples/7-segment/7-segm_raw_dynamic/7-segm_raw_dynamic.ino new file mode 100644 index 0000000..8cb03d0 --- /dev/null +++ b/Examples/7-segment/7-segm_raw_dynamic/7-segm_raw_dynamic.ino @@ -0,0 +1,124 @@ +#include + +#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 EN2_PIN 3 +#define EN3_PIN 2 + +#define DIGITS 4 + +int print_dec(uint16_t value); +int print_digit(uint8_t position, uint8_t digit); +void emulate_timer_ISR(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, EN2_PIN, EN3_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); + } +} + +void loop() +{ + for (uint16_t cnt = (int) pow(10, DIGITS) - 1; cnt > 0; cnt--) + { + print_dec(cnt); + + // This is garbage, don't use it! + for(uint8_t i = 0; i < 10; i++) + { + delay(10); + emulate_timer_ISR(); + } + } + delay(3000); +} + +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 || 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); +} diff --git a/Examples/7-segment/7-segm_raw_dynamic/7-segm_raw_dynamic.png b/Examples/7-segment/7-segm_raw_dynamic/7-segm_raw_dynamic.png new file mode 100644 index 0000000..fee62bb Binary files /dev/null and b/Examples/7-segment/7-segm_raw_dynamic/7-segm_raw_dynamic.png differ diff --git a/Examples/7-segment/7-segm_raw_dynamic/tinkercad_link.txt b/Examples/7-segment/7-segm_raw_dynamic/tinkercad_link.txt new file mode 100644 index 0000000..c24692b --- /dev/null +++ b/Examples/7-segment/7-segm_raw_dynamic/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/7eGYywVu5PG diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF new file mode 100644 index 0000000..dd885da Binary files /dev/null and b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.PDF differ diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino new file mode 100644 index 0000000..35414d5 --- /dev/null +++ b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino @@ -0,0 +1,144 @@ +#include + +#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 EN2_PIN 3 +#define EN3_PIN 2 + +#define DIGITS 4 + +int print_dec(uint16_t value); +int print_digit(uint8_t position, uint8_t digit); +void timer_init(void); +void gpio_init(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, EN2_PIN, EN3_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() +{ + gpio_init(); + timer_init(); +} + +void loop() +{ + for (uint16_t cnt = (int) pow(10, DIGITS) - 1; cnt > 0; cnt--) + { + print_dec(cnt); + delay(100); + } + delay(3000); +} + +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 || digit > 15) + { + return -1; + } + + display_value[position] = digit; + + return 0; +} + +ISR(TIMER1_OVF_vect) +{ + 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 gpio_init(void) +{ + 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); + } +} + +void timer_init(void) +{ + noInterrupts(); + + // After clearing TCCR1B the timer is stopped + TCCR1B = 0; + TCNT1 = 0; + + TCCR1A = (1 << WGM11); + TCCR1B |= (1 << WGM12) | (1 << WGM13); + TIMSK1 = (1 << TOIE1); + + // Set frequency to 1kHz + ICR1 = 1999; + TCCR1B |= (1 << CS11); + + interrupts(); +} diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.standard.hex b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.standard.hex new file mode 100644 index 0000000..ea3e572 --- /dev/null +++ b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.standard.hex @@ -0,0 +1,93 @@ +: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 diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.with_bootloader.standard.hex b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.with_bootloader.standard.hex new file mode 100644 index 0000000..443d475 --- /dev/null +++ b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.ino.with_bootloader.standard.hex @@ -0,0 +1,127 @@ +: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 diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj new file mode 100644 index 0000000..8eb8c65 Binary files /dev/null and b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj differ diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace new file mode 100644 index 0000000..1c21abc --- /dev/null +++ b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.DESKTOP-DNPR54D.Cartogan.workspace @@ -0,0 +1,101 @@ + + + + 2c0000000200000003000000ffffffffffffffffffffffffffffffffab0000000d000000d606000004040000 + + + + + + + + 542 + No + 100 + 120 + 100 + + + + + 83 + No + Yes + 83 + Yes + No + No + Yes + 0 + 83 + 100 + 83 + 0 + + + + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000100 + + + + + 2 + Yes + 2 + Yes + Yes + 00000020 + + + + + diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.VANKATA-513.ivans.workspace b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.VANKATA-513.ivans.workspace new file mode 100644 index 0000000..5545e77 --- /dev/null +++ b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.pdsprj.VANKATA-513.ivans.workspace @@ -0,0 +1,100 @@ + + + + 2c00000002000000030000000083ffff0083ffffffffffffffffffffb20000000c000000ce060000fa030000 + + + + + + + 142 + No + 100 + 120 + 100 + + + + + 83 + No + Yes + 83 + Yes + No + No + Yes + 0 + 83 + 100 + 83 + 0 + + + + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000100 + + + + + 2 + Yes + 2 + Yes + Yes + 00000020 + + + + + diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png new file mode 100644 index 0000000..26fb620 Binary files /dev/null and b/Examples/7-segment/7-segm_raw_dynamic_timer/7-segm_raw_dynamic_timer.png differ diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak b/Examples/7-segment/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak new file mode 100644 index 0000000..9bed130 Binary files /dev/null and b/Examples/7-segment/7-segm_raw_dynamic_timer/Backup Of 7-segm_raw_dynamic_timer.pdsbak differ diff --git a/Examples/7-segment/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak b/Examples/7-segment/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak new file mode 100644 index 0000000..d482f6c Binary files /dev/null and b/Examples/7-segment/7-segm_raw_dynamic_timer/Last Loaded 7-segm_raw_dynamic_timer.pdsbak differ diff --git a/Examples/7-segment/7-segm_shield/7-segm_shield.ino b/Examples/7-segment/7-segm_shield/7-segm_shield.ino new file mode 100644 index 0000000..fbd78c6 --- /dev/null +++ b/Examples/7-segment/7-segm_shield/7-segm_shield.ino @@ -0,0 +1,44 @@ +#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; +} diff --git a/Examples/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png b/Examples/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png deleted file mode 100644 index 49d7cc0..0000000 Binary files a/Examples/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png and /dev/null differ diff --git a/Examples/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino b/Examples/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino deleted file mode 100644 index 6cb7a7b..0000000 --- a/Examples/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino +++ /dev/null @@ -1,16 +0,0 @@ -#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); -} diff --git a/Examples/Big_LED_strip/Big_LED_strip.ino b/Examples/Big_LED_strip/Big_LED_strip.ino deleted file mode 100644 index d0b2c42..0000000 --- a/Examples/Big_LED_strip/Big_LED_strip.ino +++ /dev/null @@ -1,163 +0,0 @@ -#include -#include - -#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; -} diff --git a/Examples/Big_LED_strip/Big_LED_strip.png b/Examples/Big_LED_strip/Big_LED_strip.png deleted file mode 100644 index 5e6805b..0000000 Binary files a/Examples/Big_LED_strip/Big_LED_strip.png and /dev/null differ diff --git a/Examples/Big_LED_strip/elsys.ppm b/Examples/Big_LED_strip/elsys.ppm deleted file mode 100644 index f7381c3..0000000 Binary files a/Examples/Big_LED_strip/elsys.ppm and /dev/null differ diff --git a/Examples/Big_LED_strip/tinkercad_link.txt b/Examples/Big_LED_strip/tinkercad_link.txt deleted file mode 100644 index 3b1f24b..0000000 --- a/Examples/Big_LED_strip/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/eOSmRi4TA7z-bigledstrip diff --git a/Examples/Car_dodge/Car_dodge.ino b/Examples/Car_dodge/Car_dodge.ino deleted file mode 100644 index b9ff517..0000000 --- a/Examples/Car_dodge/Car_dodge.ino +++ /dev/null @@ -1,190 +0,0 @@ -#include - -#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--; - } -} diff --git a/Examples/Car_dodge/Car_dodge.png b/Examples/Car_dodge/Car_dodge.png deleted file mode 100644 index dbbbc07..0000000 Binary files a/Examples/Car_dodge/Car_dodge.png and /dev/null differ diff --git a/Examples/Car_dodge/tinkercad_link.txt b/Examples/Car_dodge/tinkercad_link.txt deleted file mode 100644 index 552eb44..0000000 --- a/Examples/Car_dodge/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/0J1F6FpWf9y diff --git a/Examples/DC_motor_and_servo/DC_motor_and_servo.ino b/Examples/DC_motor_and_servo/DC_motor_and_servo.ino deleted file mode 100644 index 8f1c9a1..0000000 --- a/Examples/DC_motor_and_servo/DC_motor_and_servo.ino +++ /dev/null @@ -1,98 +0,0 @@ -#include - -#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); -} diff --git a/Examples/DC_motor_and_servo/DC_motor_and_servo.png b/Examples/DC_motor_and_servo/DC_motor_and_servo.png deleted file mode 100644 index d3e4059..0000000 Binary files a/Examples/DC_motor_and_servo/DC_motor_and_servo.png and /dev/null differ diff --git a/Examples/DC_motor_and_servo/L293D_example_schematic_with_two_DC_motors.png b/Examples/DC_motor_and_servo/L293D_example_schematic_with_two_DC_motors.png deleted file mode 100644 index 68b04aa..0000000 Binary files a/Examples/DC_motor_and_servo/L293D_example_schematic_with_two_DC_motors.png and /dev/null differ diff --git a/Examples/DC_motor_and_servo/tinkercad_link.txt b/Examples/DC_motor_and_servo/tinkercad_link.txt deleted file mode 100644 index 73e9207..0000000 --- a/Examples/DC_motor_and_servo/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/8ef4pvh4R76 diff --git a/Examples/DC_motor_speed_control/DC_motor_speed_control.ino b/Examples/DC_motor_speed_control/DC_motor_speed_control.ino deleted file mode 100644 index 086bee0..0000000 --- a/Examples/DC_motor_speed_control/DC_motor_speed_control.ino +++ /dev/null @@ -1,21 +0,0 @@ -#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); -} diff --git a/Examples/DC_motor_speed_control/DC_motor_speed_control.png b/Examples/DC_motor_speed_control/DC_motor_speed_control.png deleted file mode 100644 index c8eb609..0000000 Binary files a/Examples/DC_motor_speed_control/DC_motor_speed_control.png and /dev/null differ diff --git a/Examples/DC_motor_speed_control/tinkercad_link.txt b/Examples/DC_motor_speed_control/tinkercad_link.txt deleted file mode 100644 index 188b34e..0000000 --- a/Examples/DC_motor_speed_control/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/3tiT8HWMh1X-dcmotorspeedcontrol diff --git a/Examples/Demo_test/Demo_test - Tinkercad - Schematic.png b/Examples/Demo_test/Demo_test - Tinkercad - Schematic.png deleted file mode 100644 index c6be61c..0000000 Binary files a/Examples/Demo_test/Demo_test - Tinkercad - Schematic.png and /dev/null differ diff --git a/Examples/Demo_test/Demo_test.ino b/Examples/Demo_test/Demo_test.ino deleted file mode 100644 index f32ab5b..0000000 --- a/Examples/Demo_test/Demo_test.ino +++ /dev/null @@ -1,79 +0,0 @@ -#include -#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); -} diff --git a/Examples/Demo_test/tinkercad_link.txt b/Examples/Demo_test/tinkercad_link.txt deleted file mode 100644 index c223182..0000000 --- a/Examples/Demo_test/tinkercad_link.txt +++ /dev/null @@ -1,2 +0,0 @@ -// Slightly different implementation -https://www.tinkercad.com/things/ffni7S7fML6 diff --git a/Examples/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png b/Examples/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png deleted file mode 100644 index e15310c..0000000 Binary files a/Examples/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png and /dev/null differ diff --git a/Examples/Digital_Blink_with_Button/Digital_Blink_with_Button.ino b/Examples/Digital_Blink_with_Button/Digital_Blink_with_Button.ino deleted file mode 100644 index e5ef2d4..0000000 --- a/Examples/Digital_Blink_with_Button/Digital_Blink_with_Button.ino +++ /dev/null @@ -1,32 +0,0 @@ -#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; - } - } -} diff --git a/Examples/EXTI0_Register_Demo/EXTI0_Register_Demo.ino b/Examples/EXTI0_Register_Demo/EXTI0_Register_Demo.ino deleted file mode 100644 index b5a762d..0000000 --- a/Examples/EXTI0_Register_Demo/EXTI0_Register_Demo.ino +++ /dev/null @@ -1,33 +0,0 @@ -#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 -} diff --git a/Examples/EXTI_Demo/EXTI_Demo.ino b/Examples/EXTI_Demo/EXTI_Demo.ino deleted file mode 100644 index 6433026..0000000 --- a/Examples/EXTI_Demo/EXTI_Demo.ino +++ /dev/null @@ -1,30 +0,0 @@ -#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)); -} diff --git a/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png b/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png new file mode 100644 index 0000000..472ae2b Binary files /dev/null and b/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png differ diff --git a/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino b/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino new file mode 100644 index 0000000..e265976 --- /dev/null +++ b/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino @@ -0,0 +1,85 @@ +#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); + } + } +} diff --git a/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt b/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt new file mode 100644 index 0000000..25a297f --- /dev/null +++ b/Examples/GPIO/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/bJ9mxNp3wXG diff --git a/Examples/GPIO/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png b/Examples/GPIO/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png new file mode 100644 index 0000000..e15310c Binary files /dev/null and b/Examples/GPIO/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png differ diff --git a/Examples/GPIO/Digital_Blink_with_Button/Digital_Blink_with_Button.ino b/Examples/GPIO/Digital_Blink_with_Button/Digital_Blink_with_Button.ino new file mode 100644 index 0000000..e5ef2d4 --- /dev/null +++ b/Examples/GPIO/Digital_Blink_with_Button/Digital_Blink_with_Button.ino @@ -0,0 +1,32 @@ +#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; + } + } +} diff --git a/Examples/GPIO/Register_Blink/Register_Blink.ino b/Examples/GPIO/Register_Blink/Register_Blink.ino new file mode 100644 index 0000000..16d6a65 --- /dev/null +++ b/Examples/GPIO/Register_Blink/Register_Blink.ino @@ -0,0 +1,12 @@ +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) +} diff --git a/Examples/Gamma_LUT_generator/Gamma_LUT_generator.ino b/Examples/Gamma_LUT_generator/Gamma_LUT_generator.ino deleted file mode 100644 index 061f7cf..0000000 --- a/Examples/Gamma_LUT_generator/Gamma_LUT_generator.ino +++ /dev/null @@ -1,24 +0,0 @@ -// 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() { - -} diff --git a/Examples/I2C/I2C_2x_interrupt_to_master/I2C_2x_with interrupt_to_master.png b/Examples/I2C/I2C_2x_interrupt_to_master/I2C_2x_with interrupt_to_master.png new file mode 100644 index 0000000..7fde137 Binary files /dev/null and b/Examples/I2C/I2C_2x_interrupt_to_master/I2C_2x_with interrupt_to_master.png differ diff --git a/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino b/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino new file mode 100644 index 0000000..faf3130 --- /dev/null +++ b/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino @@ -0,0 +1,82 @@ +#include + +#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 diff --git a/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave1/I2C_interrupt_to_master_slave1.ino b/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave1/I2C_interrupt_to_master_slave1.ino new file mode 100644 index 0000000..4beb9d5 --- /dev/null +++ b/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave1/I2C_interrupt_to_master_slave1.ino @@ -0,0 +1,61 @@ +#include + +#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; +} diff --git a/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave2/I2C_interrupt_to_master_slave2.ino b/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave2/I2C_interrupt_to_master_slave2.ino new file mode 100644 index 0000000..531d888 --- /dev/null +++ b/Examples/I2C/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave2/I2C_interrupt_to_master_slave2.ino @@ -0,0 +1,61 @@ +#include + +#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; +} diff --git a/Examples/I2C/I2C_2x_interrupt_to_master/tinkercad_link.txt b/Examples/I2C/I2C_2x_interrupt_to_master/tinkercad_link.txt new file mode 100644 index 0000000..8d653c8 --- /dev/null +++ b/Examples/I2C/I2C_2x_interrupt_to_master/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/78jf9y1YodC diff --git a/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master.png b/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master.png new file mode 100644 index 0000000..41c47c8 Binary files /dev/null and b/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master.png differ diff --git a/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino b/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino new file mode 100644 index 0000000..47b5705 --- /dev/null +++ b/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino @@ -0,0 +1,62 @@ +#include + +#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 diff --git a/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master_slave/I2C_interrupt_to_master_slave.ino b/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master_slave/I2C_interrupt_to_master_slave.ino new file mode 100644 index 0000000..4beb9d5 --- /dev/null +++ b/Examples/I2C/I2C_interrupt_to_master/I2C_interrupt_to_master_slave/I2C_interrupt_to_master_slave.ino @@ -0,0 +1,61 @@ +#include + +#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; +} diff --git a/Examples/I2C/I2C_interrupt_to_master/tinkercad_link.txt b/Examples/I2C/I2C_interrupt_to_master/tinkercad_link.txt new file mode 100644 index 0000000..ba291d4 --- /dev/null +++ b/Examples/I2C/I2C_interrupt_to_master/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/bEpoUSShgaZ diff --git a/Examples/I2C/I2C_simple_demo/I2C_simple_demo.png b/Examples/I2C/I2C_simple_demo/I2C_simple_demo.png new file mode 100644 index 0000000..dcbccd5 Binary files /dev/null and b/Examples/I2C/I2C_simple_demo/I2C_simple_demo.png differ diff --git a/Examples/I2C/I2C_simple_demo/I2C_simple_demo_master/I2C_simple_demo_master.ino b/Examples/I2C/I2C_simple_demo/I2C_simple_demo_master/I2C_simple_demo_master.ino new file mode 100644 index 0000000..a2f4273 --- /dev/null +++ b/Examples/I2C/I2C_simple_demo/I2C_simple_demo_master/I2C_simple_demo_master.ino @@ -0,0 +1,57 @@ +#include + +#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; +} diff --git a/Examples/I2C/I2C_simple_demo/I2C_simple_demo_slave/I2C_simple_demo_slave.ino b/Examples/I2C/I2C_simple_demo/I2C_simple_demo_slave/I2C_simple_demo_slave.ino new file mode 100644 index 0000000..00d6760 --- /dev/null +++ b/Examples/I2C/I2C_simple_demo/I2C_simple_demo_slave/I2C_simple_demo_slave.ino @@ -0,0 +1,51 @@ +#include + +#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"); +} diff --git a/Examples/I2C/I2C_simple_demo/tinkercad_link.txt b/Examples/I2C/I2C_simple_demo/tinkercad_link.txt new file mode 100644 index 0000000..019b53b --- /dev/null +++ b/Examples/I2C/I2C_simple_demo/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/b5ZB55WFaxX diff --git a/Examples/I2C_2x_interrupt_to_master/I2C_2x_with interrupt_to_master.png b/Examples/I2C_2x_interrupt_to_master/I2C_2x_with interrupt_to_master.png deleted file mode 100644 index 7fde137..0000000 Binary files a/Examples/I2C_2x_interrupt_to_master/I2C_2x_with interrupt_to_master.png and /dev/null differ diff --git a/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino b/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino deleted file mode 100644 index faf3130..0000000 --- a/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino +++ /dev/null @@ -1,82 +0,0 @@ -#include - -#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 diff --git a/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave1/I2C_interrupt_to_master_slave1.ino b/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave1/I2C_interrupt_to_master_slave1.ino deleted file mode 100644 index 4beb9d5..0000000 --- a/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave1/I2C_interrupt_to_master_slave1.ino +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#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; -} diff --git a/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave2/I2C_interrupt_to_master_slave2.ino b/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave2/I2C_interrupt_to_master_slave2.ino deleted file mode 100644 index 531d888..0000000 --- a/Examples/I2C_2x_interrupt_to_master/I2C_interrupt_to_master_slave2/I2C_interrupt_to_master_slave2.ino +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#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; -} diff --git a/Examples/I2C_2x_interrupt_to_master/tinkercad_link.txt b/Examples/I2C_2x_interrupt_to_master/tinkercad_link.txt deleted file mode 100644 index 8d653c8..0000000 --- a/Examples/I2C_2x_interrupt_to_master/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/78jf9y1YodC diff --git a/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master.png b/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master.png deleted file mode 100644 index 41c47c8..0000000 Binary files a/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master.png and /dev/null differ diff --git a/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino b/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino deleted file mode 100644 index 47b5705..0000000 --- a/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master_master/I2C_interrupt_to_master_master.ino +++ /dev/null @@ -1,62 +0,0 @@ -#include - -#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 diff --git a/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master_slave/I2C_interrupt_to_master_slave.ino b/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master_slave/I2C_interrupt_to_master_slave.ino deleted file mode 100644 index 4beb9d5..0000000 --- a/Examples/I2C_interrupt_to_master/I2C_interrupt_to_master_slave/I2C_interrupt_to_master_slave.ino +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#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; -} diff --git a/Examples/I2C_interrupt_to_master/tinkercad_link.txt b/Examples/I2C_interrupt_to_master/tinkercad_link.txt deleted file mode 100644 index ba291d4..0000000 --- a/Examples/I2C_interrupt_to_master/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/bEpoUSShgaZ diff --git a/Examples/I2C_simple_demo/I2C_simple_demo.png b/Examples/I2C_simple_demo/I2C_simple_demo.png deleted file mode 100644 index dcbccd5..0000000 Binary files a/Examples/I2C_simple_demo/I2C_simple_demo.png and /dev/null differ diff --git a/Examples/I2C_simple_demo/I2C_simple_demo_master/I2C_simple_demo_master.ino b/Examples/I2C_simple_demo/I2C_simple_demo_master/I2C_simple_demo_master.ino deleted file mode 100644 index a2f4273..0000000 --- a/Examples/I2C_simple_demo/I2C_simple_demo_master/I2C_simple_demo_master.ino +++ /dev/null @@ -1,57 +0,0 @@ -#include - -#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; -} diff --git a/Examples/I2C_simple_demo/I2C_simple_demo_slave/I2C_simple_demo_slave.ino b/Examples/I2C_simple_demo/I2C_simple_demo_slave/I2C_simple_demo_slave.ino deleted file mode 100644 index 00d6760..0000000 --- a/Examples/I2C_simple_demo/I2C_simple_demo_slave/I2C_simple_demo_slave.ino +++ /dev/null @@ -1,51 +0,0 @@ -#include - -#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"); -} diff --git a/Examples/I2C_simple_demo/tinkercad_link.txt b/Examples/I2C_simple_demo/tinkercad_link.txt deleted file mode 100644 index 019b53b..0000000 --- a/Examples/I2C_simple_demo/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/b5ZB55WFaxX diff --git a/Examples/LCD/LCD_bidirectional_counter/LCD_bidirectional_counter.ino b/Examples/LCD/LCD_bidirectional_counter/LCD_bidirectional_counter.ino new file mode 100644 index 0000000..1e25c5a --- /dev/null +++ b/Examples/LCD/LCD_bidirectional_counter/LCD_bidirectional_counter.ino @@ -0,0 +1,46 @@ +#include + +#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--; +} diff --git a/Examples/LCD/LCD_bidirectional_counter/LCD_bidirectional_counter.png b/Examples/LCD/LCD_bidirectional_counter/LCD_bidirectional_counter.png new file mode 100644 index 0000000..f2a4460 Binary files /dev/null and b/Examples/LCD/LCD_bidirectional_counter/LCD_bidirectional_counter.png differ diff --git a/Examples/LCD/LCD_bidirectional_counter/tinkercad_link.txt b/Examples/LCD/LCD_bidirectional_counter/tinkercad_link.txt new file mode 100644 index 0000000..1e90ecc --- /dev/null +++ b/Examples/LCD/LCD_bidirectional_counter/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/d6absXaO0GD diff --git a/Examples/LCD/LCD_custom_characters/LCD_custom_characters.ino b/Examples/LCD/LCD_custom_characters/LCD_custom_characters.ino new file mode 100644 index 0000000..ead0e15 --- /dev/null +++ b/Examples/LCD/LCD_custom_characters/LCD_custom_characters.ino @@ -0,0 +1,62 @@ +#include + +#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() +{ +} diff --git a/Examples/LCD/LCD_custom_characters/LCD_custom_characters.png b/Examples/LCD/LCD_custom_characters/LCD_custom_characters.png new file mode 100644 index 0000000..021b994 Binary files /dev/null and b/Examples/LCD/LCD_custom_characters/LCD_custom_characters.png differ diff --git a/Examples/LCD/LCD_custom_characters/tinkercad_link.txt b/Examples/LCD/LCD_custom_characters/tinkercad_link.txt new file mode 100644 index 0000000..c0f97c0 --- /dev/null +++ b/Examples/LCD/LCD_custom_characters/tinkercad_link.txt @@ -0,0 +1 @@ + https://www.tinkercad.com/things/csH65U1Tvu4 \ No newline at end of file diff --git a/Examples/LCD/LCD_scroll/LCD_scroll.ino b/Examples/LCD/LCD_scroll/LCD_scroll.ino new file mode 100644 index 0000000..5eaa1b1 --- /dev/null +++ b/Examples/LCD/LCD_scroll/LCD_scroll.ino @@ -0,0 +1,99 @@ +/* + 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 + +#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); +} diff --git a/Examples/LCD/LCD_scroll/LCD_scroll.png b/Examples/LCD/LCD_scroll/LCD_scroll.png new file mode 100644 index 0000000..9d12da2 Binary files /dev/null and b/Examples/LCD/LCD_scroll/LCD_scroll.png differ diff --git a/Examples/LCD/LCD_scroll/tinkercad_link.txt b/Examples/LCD/LCD_scroll/tinkercad_link.txt new file mode 100644 index 0000000..77fb869 --- /dev/null +++ b/Examples/LCD/LCD_scroll/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/ecuRyTU9AaJ diff --git a/Examples/LCD/LCD_scroll_multiple/LCD_scroll_multiple.ino b/Examples/LCD/LCD_scroll_multiple/LCD_scroll_multiple.ino new file mode 100644 index 0000000..21bad7c --- /dev/null +++ b/Examples/LCD/LCD_scroll_multiple/LCD_scroll_multiple.ino @@ -0,0 +1,79 @@ +#include +#include + +#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); + } +} diff --git a/Examples/LCD/LCD_scroll_multiple/LCD_scroll_multiple.png b/Examples/LCD/LCD_scroll_multiple/LCD_scroll_multiple.png new file mode 100644 index 0000000..74180c4 Binary files /dev/null and b/Examples/LCD/LCD_scroll_multiple/LCD_scroll_multiple.png differ diff --git a/Examples/LCD/LCD_scroll_multiple/tinkercad_link.txt b/Examples/LCD/LCD_scroll_multiple/tinkercad_link.txt new file mode 100644 index 0000000..2770292 --- /dev/null +++ b/Examples/LCD/LCD_scroll_multiple/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/des9SoAMtAC diff --git a/Examples/LCD/LCD_without_library/LCD_without_library.ino b/Examples/LCD/LCD_without_library/LCD_without_library.ino new file mode 100644 index 0000000..b704090 --- /dev/null +++ b/Examples/LCD/LCD_without_library/LCD_without_library.ino @@ -0,0 +1,126 @@ +#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 +} diff --git a/Examples/LCD/LCD_without_library/LCD_without_library.png b/Examples/LCD/LCD_without_library/LCD_without_library.png new file mode 100644 index 0000000..9d12da2 Binary files /dev/null and b/Examples/LCD/LCD_without_library/LCD_without_library.png differ diff --git a/Examples/LCD/LCD_without_library/tinkercad_link.txt b/Examples/LCD/LCD_without_library/tinkercad_link.txt new file mode 100644 index 0000000..aa8b791 --- /dev/null +++ b/Examples/LCD/LCD_without_library/tinkercad_link.txt @@ -0,0 +1 @@ + https://www.tinkercad.com/things/9LSofZh54nf \ No newline at end of file diff --git a/Examples/LCD/LCD_without_library_simple/LCD_without_library_simple.ino b/Examples/LCD/LCD_without_library_simple/LCD_without_library_simple.ino new file mode 100644 index 0000000..1227a1e --- /dev/null +++ b/Examples/LCD/LCD_without_library_simple/LCD_without_library_simple.ino @@ -0,0 +1,77 @@ +#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 +} diff --git a/Examples/LCD/LCD_without_library_simple/LCD_without_library_simple.png b/Examples/LCD/LCD_without_library_simple/LCD_without_library_simple.png new file mode 100644 index 0000000..9d12da2 Binary files /dev/null and b/Examples/LCD/LCD_without_library_simple/LCD_without_library_simple.png differ diff --git a/Examples/LCD/LCD_without_library_simple/tinkercad_link.txt b/Examples/LCD/LCD_without_library_simple/tinkercad_link.txt new file mode 100644 index 0000000..1afe472 --- /dev/null +++ b/Examples/LCD/LCD_without_library_simple/tinkercad_link.txt @@ -0,0 +1 @@ + https://www.tinkercad.com/things/enhJJzIeHyr \ No newline at end of file diff --git a/Examples/LCD_bidirectional_counter/LCD_bidirectional_counter.ino b/Examples/LCD_bidirectional_counter/LCD_bidirectional_counter.ino deleted file mode 100644 index 1e25c5a..0000000 --- a/Examples/LCD_bidirectional_counter/LCD_bidirectional_counter.ino +++ /dev/null @@ -1,46 +0,0 @@ -#include - -#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--; -} diff --git a/Examples/LCD_bidirectional_counter/LCD_bidirectional_counter.png b/Examples/LCD_bidirectional_counter/LCD_bidirectional_counter.png deleted file mode 100644 index f2a4460..0000000 Binary files a/Examples/LCD_bidirectional_counter/LCD_bidirectional_counter.png and /dev/null differ diff --git a/Examples/LCD_bidirectional_counter/tinkercad_link.txt b/Examples/LCD_bidirectional_counter/tinkercad_link.txt deleted file mode 100644 index 1e90ecc..0000000 --- a/Examples/LCD_bidirectional_counter/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/d6absXaO0GD diff --git a/Examples/LCD_custom_characters/LCD_custom_characters.ino b/Examples/LCD_custom_characters/LCD_custom_characters.ino deleted file mode 100644 index ead0e15..0000000 --- a/Examples/LCD_custom_characters/LCD_custom_characters.ino +++ /dev/null @@ -1,62 +0,0 @@ -#include - -#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() -{ -} diff --git a/Examples/LCD_custom_characters/LCD_custom_characters.png b/Examples/LCD_custom_characters/LCD_custom_characters.png deleted file mode 100644 index 021b994..0000000 Binary files a/Examples/LCD_custom_characters/LCD_custom_characters.png and /dev/null differ diff --git a/Examples/LCD_custom_characters/tinkercad_link.txt b/Examples/LCD_custom_characters/tinkercad_link.txt deleted file mode 100644 index c0f97c0..0000000 --- a/Examples/LCD_custom_characters/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ - https://www.tinkercad.com/things/csH65U1Tvu4 \ No newline at end of file diff --git a/Examples/LCD_scroll/LCD_scroll.ino b/Examples/LCD_scroll/LCD_scroll.ino deleted file mode 100644 index 5eaa1b1..0000000 --- a/Examples/LCD_scroll/LCD_scroll.ino +++ /dev/null @@ -1,99 +0,0 @@ -/* - 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 - -#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); -} diff --git a/Examples/LCD_scroll/LCD_scroll.png b/Examples/LCD_scroll/LCD_scroll.png deleted file mode 100644 index 9d12da2..0000000 Binary files a/Examples/LCD_scroll/LCD_scroll.png and /dev/null differ diff --git a/Examples/LCD_scroll/tinkercad_link.txt b/Examples/LCD_scroll/tinkercad_link.txt deleted file mode 100644 index 77fb869..0000000 --- a/Examples/LCD_scroll/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/ecuRyTU9AaJ diff --git a/Examples/LCD_scroll_multiple/LCD_scroll_multiple.ino b/Examples/LCD_scroll_multiple/LCD_scroll_multiple.ino deleted file mode 100644 index 21bad7c..0000000 --- a/Examples/LCD_scroll_multiple/LCD_scroll_multiple.ino +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include - -#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); - } -} diff --git a/Examples/LCD_scroll_multiple/LCD_scroll_multiple.png b/Examples/LCD_scroll_multiple/LCD_scroll_multiple.png deleted file mode 100644 index 74180c4..0000000 Binary files a/Examples/LCD_scroll_multiple/LCD_scroll_multiple.png and /dev/null differ diff --git a/Examples/LCD_scroll_multiple/tinkercad_link.txt b/Examples/LCD_scroll_multiple/tinkercad_link.txt deleted file mode 100644 index 2770292..0000000 --- a/Examples/LCD_scroll_multiple/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/des9SoAMtAC diff --git a/Examples/LCD_without_library/LCD_without_library.ino b/Examples/LCD_without_library/LCD_without_library.ino deleted file mode 100644 index b704090..0000000 --- a/Examples/LCD_without_library/LCD_without_library.ino +++ /dev/null @@ -1,126 +0,0 @@ -#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 -} diff --git a/Examples/LCD_without_library/LCD_without_library.png b/Examples/LCD_without_library/LCD_without_library.png deleted file mode 100644 index 9d12da2..0000000 Binary files a/Examples/LCD_without_library/LCD_without_library.png and /dev/null differ diff --git a/Examples/LCD_without_library/tinkercad_link.txt b/Examples/LCD_without_library/tinkercad_link.txt deleted file mode 100644 index aa8b791..0000000 --- a/Examples/LCD_without_library/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ - https://www.tinkercad.com/things/9LSofZh54nf \ No newline at end of file diff --git a/Examples/LCD_without_library_simple/LCD_without_library_simple.ino b/Examples/LCD_without_library_simple/LCD_without_library_simple.ino deleted file mode 100644 index 1227a1e..0000000 --- a/Examples/LCD_without_library_simple/LCD_without_library_simple.ino +++ /dev/null @@ -1,77 +0,0 @@ -#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 -} diff --git a/Examples/LCD_without_library_simple/LCD_without_library_simple.png b/Examples/LCD_without_library_simple/LCD_without_library_simple.png deleted file mode 100644 index 9d12da2..0000000 Binary files a/Examples/LCD_without_library_simple/LCD_without_library_simple.png and /dev/null differ diff --git a/Examples/LCD_without_library_simple/tinkercad_link.txt b/Examples/LCD_without_library_simple/tinkercad_link.txt deleted file mode 100644 index 1afe472..0000000 --- a/Examples/LCD_without_library_simple/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ - https://www.tinkercad.com/things/enhJJzIeHyr \ No newline at end of file diff --git a/Examples/LED_Strip_Moving_LED_-_Interrupt/LED Strip Moving LED - Interrupt Tinkercad.png b/Examples/LED_Strip_Moving_LED_-_Interrupt/LED Strip Moving LED - Interrupt Tinkercad.png deleted file mode 100644 index 1284fcc..0000000 Binary files a/Examples/LED_Strip_Moving_LED_-_Interrupt/LED Strip Moving LED - Interrupt Tinkercad.png and /dev/null differ diff --git a/Examples/LED_Strip_Moving_LED_-_Interrupt/LED_Strip_Moving_LED_-_Interrupt.ino b/Examples/LED_Strip_Moving_LED_-_Interrupt/LED_Strip_Moving_LED_-_Interrupt.ino deleted file mode 100644 index 5fdcdb9..0000000 --- a/Examples/LED_Strip_Moving_LED_-_Interrupt/LED_Strip_Moving_LED_-_Interrupt.ino +++ /dev/null @@ -1,45 +0,0 @@ -#include -#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(); -} diff --git a/Examples/LED_Strip_Moving_LED_-_Polling/LED Strip Moving LED - Polling Tinkercad.png b/Examples/LED_Strip_Moving_LED_-_Polling/LED Strip Moving LED - Polling Tinkercad.png deleted file mode 100644 index 70f3c24..0000000 Binary files a/Examples/LED_Strip_Moving_LED_-_Polling/LED Strip Moving LED - Polling Tinkercad.png and /dev/null differ diff --git a/Examples/LED_Strip_Moving_LED_-_Polling/LED_Strip_Moving_LED_-_Polling.ino b/Examples/LED_Strip_Moving_LED_-_Polling/LED_Strip_Moving_LED_-_Polling.ino deleted file mode 100644 index 6b452fd..0000000 --- a/Examples/LED_Strip_Moving_LED_-_Polling/LED_Strip_Moving_LED_-_Polling.ino +++ /dev/null @@ -1,42 +0,0 @@ -#include -#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(); -} diff --git a/Examples/LED_strip/Big_LED_strip/Big_LED_strip.ino b/Examples/LED_strip/Big_LED_strip/Big_LED_strip.ino new file mode 100644 index 0000000..d0b2c42 --- /dev/null +++ b/Examples/LED_strip/Big_LED_strip/Big_LED_strip.ino @@ -0,0 +1,163 @@ +#include +#include + +#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; +} diff --git a/Examples/LED_strip/Big_LED_strip/Big_LED_strip.png b/Examples/LED_strip/Big_LED_strip/Big_LED_strip.png new file mode 100644 index 0000000..5e6805b Binary files /dev/null and b/Examples/LED_strip/Big_LED_strip/Big_LED_strip.png differ diff --git a/Examples/LED_strip/Big_LED_strip/elsys.ppm b/Examples/LED_strip/Big_LED_strip/elsys.ppm new file mode 100644 index 0000000..f7381c3 Binary files /dev/null and b/Examples/LED_strip/Big_LED_strip/elsys.ppm differ diff --git a/Examples/LED_strip/Big_LED_strip/tinkercad_link.txt b/Examples/LED_strip/Big_LED_strip/tinkercad_link.txt new file mode 100644 index 0000000..3b1f24b --- /dev/null +++ b/Examples/LED_strip/Big_LED_strip/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/eOSmRi4TA7z-bigledstrip diff --git a/Examples/LED_strip/Car_dodge/Car_dodge.ino b/Examples/LED_strip/Car_dodge/Car_dodge.ino new file mode 100644 index 0000000..b9ff517 --- /dev/null +++ b/Examples/LED_strip/Car_dodge/Car_dodge.ino @@ -0,0 +1,190 @@ +#include + +#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--; + } +} diff --git a/Examples/LED_strip/Car_dodge/Car_dodge.png b/Examples/LED_strip/Car_dodge/Car_dodge.png new file mode 100644 index 0000000..dbbbc07 Binary files /dev/null and b/Examples/LED_strip/Car_dodge/Car_dodge.png differ diff --git a/Examples/LED_strip/Car_dodge/tinkercad_link.txt b/Examples/LED_strip/Car_dodge/tinkercad_link.txt new file mode 100644 index 0000000..552eb44 --- /dev/null +++ b/Examples/LED_strip/Car_dodge/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/0J1F6FpWf9y diff --git a/Examples/LED_strip/Gamma_LUT_generator/Gamma_LUT_generator.ino b/Examples/LED_strip/Gamma_LUT_generator/Gamma_LUT_generator.ino new file mode 100644 index 0000000..061f7cf --- /dev/null +++ b/Examples/LED_strip/Gamma_LUT_generator/Gamma_LUT_generator.ino @@ -0,0 +1,24 @@ +// 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() { + +} diff --git a/Examples/LED_strip/LED_Strip_Moving_LED_-_Interrupt/LED Strip Moving LED - Interrupt Tinkercad.png b/Examples/LED_strip/LED_Strip_Moving_LED_-_Interrupt/LED Strip Moving LED - Interrupt Tinkercad.png new file mode 100644 index 0000000..1284fcc Binary files /dev/null and b/Examples/LED_strip/LED_Strip_Moving_LED_-_Interrupt/LED Strip Moving LED - Interrupt Tinkercad.png differ diff --git a/Examples/LED_strip/LED_Strip_Moving_LED_-_Interrupt/LED_Strip_Moving_LED_-_Interrupt.ino b/Examples/LED_strip/LED_Strip_Moving_LED_-_Interrupt/LED_Strip_Moving_LED_-_Interrupt.ino new file mode 100644 index 0000000..5fdcdb9 --- /dev/null +++ b/Examples/LED_strip/LED_Strip_Moving_LED_-_Interrupt/LED_Strip_Moving_LED_-_Interrupt.ino @@ -0,0 +1,45 @@ +#include +#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(); +} diff --git a/Examples/LED_strip/LED_Strip_Moving_LED_-_Polling/LED Strip Moving LED - Polling Tinkercad.png b/Examples/LED_strip/LED_Strip_Moving_LED_-_Polling/LED Strip Moving LED - Polling Tinkercad.png new file mode 100644 index 0000000..70f3c24 Binary files /dev/null and b/Examples/LED_strip/LED_Strip_Moving_LED_-_Polling/LED Strip Moving LED - Polling Tinkercad.png differ diff --git a/Examples/LED_strip/LED_Strip_Moving_LED_-_Polling/LED_Strip_Moving_LED_-_Polling.ino b/Examples/LED_strip/LED_Strip_Moving_LED_-_Polling/LED_Strip_Moving_LED_-_Polling.ino new file mode 100644 index 0000000..6b452fd --- /dev/null +++ b/Examples/LED_strip/LED_Strip_Moving_LED_-_Polling/LED_Strip_Moving_LED_-_Polling.ino @@ -0,0 +1,42 @@ +#include +#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(); +} diff --git a/Examples/LED_strip/PWM_Gamma_Correction/PWM_Gamma_Correction.ino b/Examples/LED_strip/PWM_Gamma_Correction/PWM_Gamma_Correction.ino new file mode 100644 index 0000000..bbac89c --- /dev/null +++ b/Examples/LED_strip/PWM_Gamma_Correction/PWM_Gamma_Correction.ino @@ -0,0 +1,21 @@ +#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); + } +} diff --git a/Examples/LED_strip/RGB_Gamma_Correction/RGB_Gamma_Correction.ino b/Examples/LED_strip/RGB_Gamma_Correction/RGB_Gamma_Correction.ino new file mode 100644 index 0000000..ce8837f --- /dev/null +++ b/Examples/LED_strip/RGB_Gamma_Correction/RGB_Gamma_Correction.ino @@ -0,0 +1,34 @@ +#include +#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); + } +} diff --git a/Examples/LED_strip/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino b/Examples/LED_strip/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino new file mode 100644 index 0000000..d278296 --- /dev/null +++ b/Examples/LED_strip/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino @@ -0,0 +1,124 @@ +#include +#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 + }; +*/ diff --git a/Examples/LED_strip/TUES-LED_strip_1/TUES-LED_strip_1.ino b/Examples/LED_strip/TUES-LED_strip_1/TUES-LED_strip_1.ino new file mode 100644 index 0000000..2426e6a --- /dev/null +++ b/Examples/LED_strip/TUES-LED_strip_1/TUES-LED_strip_1.ino @@ -0,0 +1,132 @@ +#include +#include + +#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; +} diff --git a/Examples/LED_strip/TUES-LED_strip_1/TUES-LED_strip_1.png b/Examples/LED_strip/TUES-LED_strip_1/TUES-LED_strip_1.png new file mode 100644 index 0000000..fd314f7 Binary files /dev/null and b/Examples/LED_strip/TUES-LED_strip_1/TUES-LED_strip_1.png differ diff --git a/Examples/LED_strip/TUES-LED_strip_1/WS2812B.pdf b/Examples/LED_strip/TUES-LED_strip_1/WS2812B.pdf new file mode 100644 index 0000000..4925af6 Binary files /dev/null and b/Examples/LED_strip/TUES-LED_strip_1/WS2812B.pdf differ diff --git a/Examples/LED_strip/TUES-LED_strip_1/mona_lisa.ppm b/Examples/LED_strip/TUES-LED_strip_1/mona_lisa.ppm new file mode 100644 index 0000000..2be5d2a Binary files /dev/null and b/Examples/LED_strip/TUES-LED_strip_1/mona_lisa.ppm differ diff --git a/Examples/LED_strip/TUES-LED_strip_1/nozdra.ppm b/Examples/LED_strip/TUES-LED_strip_1/nozdra.ppm new file mode 100644 index 0000000..dbbd1b3 --- /dev/null +++ b/Examples/LED_strip/TUES-LED_strip_1/nozdra.ppm @@ -0,0 +1,5 @@ +P6 +# Created by GIMP version 2.10.22 PNM plug-in +16 3 +255 +¹x¼{“¾~˜¾~˜¼}˜º{–¸y–´u’±r¯p«l‰§h…¢aœ[yšWv›Vu¸w»z’¼|–¼|–»{–¹y”µv‘²sŽ®oŒ¬mŠ¤e‚ a~›Zx–Us”Qp—Rq¹uŒºy‘½|”»{•ºz•¸x“µu°qŒ­n‹ªkˆ£d _}›Zx—Ts•Rq™Su \ No newline at end of file diff --git a/Examples/LED_strip/TUES-LED_strip_1/rick_astley.jpg b/Examples/LED_strip/TUES-LED_strip_1/rick_astley.jpg new file mode 100644 index 0000000..fd8e530 Binary files /dev/null and b/Examples/LED_strip/TUES-LED_strip_1/rick_astley.jpg differ diff --git a/Examples/LED_strip/TUES-LED_strip_1/sako.ppm.txt b/Examples/LED_strip/TUES-LED_strip_1/sako.ppm.txt new file mode 100644 index 0000000..c3967d2 --- /dev/null +++ b/Examples/LED_strip/TUES-LED_strip_1/sako.ppm.txt @@ -0,0 +1,13 @@ +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 diff --git a/Examples/LED_strip/TUES-LED_strip_1/tinkercad_link.txt b/Examples/LED_strip/TUES-LED_strip_1/tinkercad_link.txt new file mode 100644 index 0000000..e186c83 --- /dev/null +++ b/Examples/LED_strip/TUES-LED_strip_1/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/4uzv4lu12yT diff --git a/Examples/PWM_Gamma_Correction/PWM_Gamma_Correction.ino b/Examples/PWM_Gamma_Correction/PWM_Gamma_Correction.ino deleted file mode 100644 index bbac89c..0000000 --- a/Examples/PWM_Gamma_Correction/PWM_Gamma_Correction.ino +++ /dev/null @@ -1,21 +0,0 @@ -#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); - } -} diff --git a/Examples/RGB_Gamma_Correction/RGB_Gamma_Correction.ino b/Examples/RGB_Gamma_Correction/RGB_Gamma_Correction.ino deleted file mode 100644 index ce8837f..0000000 --- a/Examples/RGB_Gamma_Correction/RGB_Gamma_Correction.ino +++ /dev/null @@ -1,34 +0,0 @@ -#include -#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); - } -} diff --git a/Examples/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino b/Examples/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino deleted file mode 100644 index d278296..0000000 --- a/Examples/RGB_Gamma_Correction_Multicolor/RGB_Gamma_Correction_Multicolor.ino +++ /dev/null @@ -1,124 +0,0 @@ -#include -#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 - }; -*/ diff --git a/Examples/Register_Blink/Register_Blink.ino b/Examples/Register_Blink/Register_Blink.ino deleted file mode 100644 index 16d6a65..0000000 --- a/Examples/Register_Blink/Register_Blink.ino +++ /dev/null @@ -1,12 +0,0 @@ -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) -} diff --git a/Examples/Stepper_demo/Backup Of Stepper_demo.pdsbak b/Examples/Stepper_demo/Backup Of Stepper_demo.pdsbak deleted file mode 100644 index 6ba6106..0000000 Binary files a/Examples/Stepper_demo/Backup Of Stepper_demo.pdsbak and /dev/null differ diff --git a/Examples/Stepper_demo/Drive.png b/Examples/Stepper_demo/Drive.png deleted file mode 100644 index 8c3a0a3..0000000 Binary files a/Examples/Stepper_demo/Drive.png and /dev/null differ diff --git a/Examples/Stepper_demo/Last Loaded Stepper_demo.pdsbak b/Examples/Stepper_demo/Last Loaded Stepper_demo.pdsbak deleted file mode 100644 index 5d39a8f..0000000 Binary files a/Examples/Stepper_demo/Last Loaded Stepper_demo.pdsbak and /dev/null differ diff --git a/Examples/Stepper_demo/Stepper_demo.PDF b/Examples/Stepper_demo/Stepper_demo.PDF deleted file mode 100644 index 101ca36..0000000 Binary files a/Examples/Stepper_demo/Stepper_demo.PDF and /dev/null differ diff --git a/Examples/Stepper_demo/Stepper_demo.pdsprj b/Examples/Stepper_demo/Stepper_demo.pdsprj deleted file mode 100644 index d0b5607..0000000 Binary files a/Examples/Stepper_demo/Stepper_demo.pdsprj and /dev/null differ diff --git a/Examples/Stepper_demo/Stepper_demo.pdsprj.DESKTOP-Q6QBCIN.Cartogan.workspace b/Examples/Stepper_demo/Stepper_demo.pdsprj.DESKTOP-Q6QBCIN.Cartogan.workspace deleted file mode 100644 index b54f9c5..0000000 --- a/Examples/Stepper_demo/Stepper_demo.pdsprj.DESKTOP-Q6QBCIN.Cartogan.workspace +++ /dev/null @@ -1,127 +0,0 @@ - - - - 2c0000000000000001000000ffffffffffffffffffffffffffffffff670000001a000000de06000010040000 - - - - - - - 524 - No - 107 - 100 - - - - - 87 - No - Yes - 87 - Yes - No - No - Yes - 0 - 87 - 100 - 87 - 0 - - - - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000000 - - - - - 2 - Yes - 2 - Yes - Yes - 00000100 - - - - - 2 - Yes - 2 - Yes - Yes - 00000020 - - - - - No - Yes - No - No - Yes - No - 0 - - - - - 636 - No - Yes - 636 - Yes - Yes - No - No - No - 0 - 636 - 100 - 0 - - - - - diff --git a/Examples/Stepper_demo/bipolar-vs-unipolar-stepper-motors.gif b/Examples/Stepper_demo/bipolar-vs-unipolar-stepper-motors.gif deleted file mode 100644 index a13be32..0000000 Binary files a/Examples/Stepper_demo/bipolar-vs-unipolar-stepper-motors.gif and /dev/null differ diff --git a/Examples/Stepper_demo/stepper_demo_delay/stepper_demo_delay.ino b/Examples/Stepper_demo/stepper_demo_delay/stepper_demo_delay.ino deleted file mode 100644 index b7ee2b0..0000000 --- a/Examples/Stepper_demo/stepper_demo_delay/stepper_demo_delay.ino +++ /dev/null @@ -1,68 +0,0 @@ -#include - -#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); -} diff --git a/Examples/Stepper_demo/stepper_demo_timer/stepper_demo_timer.ino b/Examples/Stepper_demo/stepper_demo_timer/stepper_demo_timer.ino deleted file mode 100644 index a4e8741..0000000 --- a/Examples/Stepper_demo/stepper_demo_timer/stepper_demo_timer.ino +++ /dev/null @@ -1,99 +0,0 @@ -#include - -#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); -} - diff --git a/Examples/Stepper_demo/stepper_motor.jpg b/Examples/Stepper_demo/stepper_motor.jpg deleted file mode 100644 index b760c51..0000000 Binary files a/Examples/Stepper_demo/stepper_motor.jpg and /dev/null differ diff --git a/Examples/Stepper_demo/stepper_motor_animated.gif b/Examples/Stepper_demo/stepper_motor_animated.gif deleted file mode 100644 index e0ec1bb..0000000 Binary files a/Examples/Stepper_demo/stepper_motor_animated.gif and /dev/null differ diff --git a/Examples/TUES-LED_strip_1/TUES-LED_strip_1.ino b/Examples/TUES-LED_strip_1/TUES-LED_strip_1.ino deleted file mode 100644 index 2426e6a..0000000 --- a/Examples/TUES-LED_strip_1/TUES-LED_strip_1.ino +++ /dev/null @@ -1,132 +0,0 @@ -#include -#include - -#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; -} diff --git a/Examples/TUES-LED_strip_1/TUES-LED_strip_1.png b/Examples/TUES-LED_strip_1/TUES-LED_strip_1.png deleted file mode 100644 index fd314f7..0000000 Binary files a/Examples/TUES-LED_strip_1/TUES-LED_strip_1.png and /dev/null differ diff --git a/Examples/TUES-LED_strip_1/WS2812B.pdf b/Examples/TUES-LED_strip_1/WS2812B.pdf deleted file mode 100644 index 4925af6..0000000 Binary files a/Examples/TUES-LED_strip_1/WS2812B.pdf and /dev/null differ diff --git a/Examples/TUES-LED_strip_1/mona_lisa.ppm b/Examples/TUES-LED_strip_1/mona_lisa.ppm deleted file mode 100644 index 2be5d2a..0000000 Binary files a/Examples/TUES-LED_strip_1/mona_lisa.ppm and /dev/null differ diff --git a/Examples/TUES-LED_strip_1/nozdra.ppm b/Examples/TUES-LED_strip_1/nozdra.ppm deleted file mode 100644 index dbbd1b3..0000000 --- a/Examples/TUES-LED_strip_1/nozdra.ppm +++ /dev/null @@ -1,5 +0,0 @@ -P6 -# Created by GIMP version 2.10.22 PNM plug-in -16 3 -255 -¹x¼{“¾~˜¾~˜¼}˜º{–¸y–´u’±r¯p«l‰§h…¢aœ[yšWv›Vu¸w»z’¼|–¼|–»{–¹y”µv‘²sŽ®oŒ¬mŠ¤e‚ a~›Zx–Us”Qp—Rq¹uŒºy‘½|”»{•ºz•¸x“µu°qŒ­n‹ªkˆ£d _}›Zx—Ts•Rq™Su \ No newline at end of file diff --git a/Examples/TUES-LED_strip_1/rick_astley.jpg b/Examples/TUES-LED_strip_1/rick_astley.jpg deleted file mode 100644 index fd8e530..0000000 Binary files a/Examples/TUES-LED_strip_1/rick_astley.jpg and /dev/null differ diff --git a/Examples/TUES-LED_strip_1/sako.ppm.txt b/Examples/TUES-LED_strip_1/sako.ppm.txt deleted file mode 100644 index c3967d2..0000000 --- a/Examples/TUES-LED_strip_1/sako.ppm.txt +++ /dev/null @@ -1,13 +0,0 @@ -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 diff --git a/Examples/TUES-LED_strip_1/tinkercad_link.txt b/Examples/TUES-LED_strip_1/tinkercad_link.txt deleted file mode 100644 index e186c83..0000000 --- a/Examples/TUES-LED_strip_1/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/4uzv4lu12yT diff --git a/Examples/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.ino b/Examples/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.ino deleted file mode 100644 index d603aa4..0000000 --- a/Examples/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.ino +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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; - } -} diff --git a/Examples/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.png b/Examples/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.png deleted file mode 100644 index bebc3db..0000000 Binary files a/Examples/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.png and /dev/null differ diff --git a/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.ino b/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.ino deleted file mode 100644 index efa2118..0000000 --- a/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.ino +++ /dev/null @@ -1,62 +0,0 @@ -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); -} diff --git a/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.png b/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.png deleted file mode 100644 index c664e27..0000000 Binary files a/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.png and /dev/null differ diff --git a/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/tinkercad_link.txt b/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/tinkercad_link.txt deleted file mode 100644 index a0b579d..0000000 --- a/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/c8JLkjplQKy diff --git a/Examples/Timer_1_CompMatchA_Interrupt/Timer_1_CompMatchA_Interrupt.ino b/Examples/Timer_1_CompMatchA_Interrupt/Timer_1_CompMatchA_Interrupt.ino deleted file mode 100644 index 99a5bfc..0000000 --- a/Examples/Timer_1_CompMatchA_Interrupt/Timer_1_CompMatchA_Interrupt.ino +++ /dev/null @@ -1,52 +0,0 @@ -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() -{ - -} diff --git a/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.ino b/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.ino deleted file mode 100644 index e6bb3ef..0000000 --- a/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.ino +++ /dev/null @@ -1,61 +0,0 @@ -#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); - } -} diff --git a/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.png b/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.png deleted file mode 100644 index fc72730..0000000 Binary files a/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.png and /dev/null differ diff --git a/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/tinkercad_link.txt b/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/tinkercad_link.txt deleted file mode 100644 index aa75c78..0000000 --- a/Examples/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/abCdiMvkJs6 diff --git a/Examples/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.ino b/Examples/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.ino deleted file mode 100644 index 4f1e4b7..0000000 --- a/Examples/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.ino +++ /dev/null @@ -1,73 +0,0 @@ -#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; - } -} diff --git a/Examples/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.png b/Examples/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.png deleted file mode 100644 index 31a4373..0000000 Binary files a/Examples/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.png and /dev/null differ diff --git a/Examples/Timer_DIP_switch_frequency/tinkercad_link.txt b/Examples/Timer_DIP_switch_frequency/tinkercad_link.txt deleted file mode 100644 index 0095544..0000000 --- a/Examples/Timer_DIP_switch_frequency/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ - https://www.tinkercad.com/things/2g5g32R3Fb7 diff --git a/Examples/Timer_PWM_10kHz_D25/Timer_PWM_10kHz_D25.ino b/Examples/Timer_PWM_10kHz_D25/Timer_PWM_10kHz_D25.ino deleted file mode 100644 index 636d6cc..0000000 --- a/Examples/Timer_PWM_10kHz_D25/Timer_PWM_10kHz_D25.ino +++ /dev/null @@ -1,23 +0,0 @@ -// 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() { - -} diff --git a/Examples/Timer_PWM_10kHz_D50/Timer_PWM_10kHz_D50.ino b/Examples/Timer_PWM_10kHz_D50/Timer_PWM_10kHz_D50.ino deleted file mode 100644 index 6b60731..0000000 --- a/Examples/Timer_PWM_10kHz_D50/Timer_PWM_10kHz_D50.ino +++ /dev/null @@ -1,23 +0,0 @@ -// 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() { - -} diff --git a/Examples/Timer_PWM_2Hz_D25/Timer_PWM_2Hz_D25.ino b/Examples/Timer_PWM_2Hz_D25/Timer_PWM_2Hz_D25.ino deleted file mode 100644 index ca156da..0000000 --- a/Examples/Timer_PWM_2Hz_D25/Timer_PWM_2Hz_D25.ino +++ /dev/null @@ -1,23 +0,0 @@ -// 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() { - -} diff --git a/Examples/Timer_PWM_2Hz_D80/Timer_PWM_2Hz_D80.ino b/Examples/Timer_PWM_2Hz_D80/Timer_PWM_2Hz_D80.ino deleted file mode 100644 index 4698a58..0000000 --- a/Examples/Timer_PWM_2Hz_D80/Timer_PWM_2Hz_D80.ino +++ /dev/null @@ -1,23 +0,0 @@ -// 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() { - -} diff --git a/Examples/UART-Send/Introduction-to-UART-Packet-Frame-and-Bits-2.png b/Examples/UART-Send/Introduction-to-UART-Packet-Frame-and-Bits-2.png deleted file mode 100644 index b40e213..0000000 Binary files a/Examples/UART-Send/Introduction-to-UART-Packet-Frame-and-Bits-2.png and /dev/null differ diff --git a/Examples/UART-Send/UART-Send.ino b/Examples/UART-Send/UART-Send.ino deleted file mode 100644 index 9470a17..0000000 --- a/Examples/UART-Send/UART-Send.ino +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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); -} diff --git a/Examples/UART-Send/UART-Signal-Sending_ASCII-V-CR-LF.bmp b/Examples/UART-Send/UART-Signal-Sending_ASCII-V-CR-LF.bmp deleted file mode 100644 index 30b99e2..0000000 Binary files a/Examples/UART-Send/UART-Signal-Sending_ASCII-V-CR-LF.bmp and /dev/null differ diff --git a/Examples/UART-Send/UART-Signal-Sending_ASCII-V-Zoomed.bmp b/Examples/UART-Send/UART-Signal-Sending_ASCII-V-Zoomed.bmp deleted file mode 100644 index 2ea3b2c..0000000 Binary files a/Examples/UART-Send/UART-Signal-Sending_ASCII-V-Zoomed.bmp and /dev/null differ diff --git a/Examples/UART-Send/UART-Signal-Sending_ASCII-V.bmp b/Examples/UART-Send/UART-Signal-Sending_ASCII-V.bmp deleted file mode 100644 index bda4c65..0000000 Binary files a/Examples/UART-Send/UART-Signal-Sending_ASCII-V.bmp and /dev/null differ diff --git a/Examples/UART-Send/UnderstandingUART.jpg b/Examples/UART-Send/UnderstandingUART.jpg deleted file mode 100644 index 3cdb6c1..0000000 Binary files a/Examples/UART-Send/UnderstandingUART.jpg and /dev/null differ diff --git a/Examples/UART/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png b/Examples/UART/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png new file mode 100644 index 0000000..49d7cc0 Binary files /dev/null and b/Examples/UART/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png differ diff --git a/Examples/UART/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino b/Examples/UART/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino new file mode 100644 index 0000000..6cb7a7b --- /dev/null +++ b/Examples/UART/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino @@ -0,0 +1,16 @@ +#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); +} diff --git a/Examples/UART/UART-Send/Introduction-to-UART-Packet-Frame-and-Bits-2.png b/Examples/UART/UART-Send/Introduction-to-UART-Packet-Frame-and-Bits-2.png new file mode 100644 index 0000000..b40e213 Binary files /dev/null and b/Examples/UART/UART-Send/Introduction-to-UART-Packet-Frame-and-Bits-2.png differ diff --git a/Examples/UART/UART-Send/UART-Send.ino b/Examples/UART/UART-Send/UART-Send.ino new file mode 100644 index 0000000..9470a17 --- /dev/null +++ b/Examples/UART/UART-Send/UART-Send.ino @@ -0,0 +1,24 @@ +/* + * 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); +} diff --git a/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V-CR-LF.bmp b/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V-CR-LF.bmp new file mode 100644 index 0000000..30b99e2 Binary files /dev/null and b/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V-CR-LF.bmp differ diff --git a/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V-Zoomed.bmp b/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V-Zoomed.bmp new file mode 100644 index 0000000..2ea3b2c Binary files /dev/null and b/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V-Zoomed.bmp differ diff --git a/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V.bmp b/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V.bmp new file mode 100644 index 0000000..bda4c65 Binary files /dev/null and b/Examples/UART/UART-Send/UART-Signal-Sending_ASCII-V.bmp differ diff --git a/Examples/UART/UART-Send/UnderstandingUART.jpg b/Examples/UART/UART-Send/UnderstandingUART.jpg new file mode 100644 index 0000000..3cdb6c1 Binary files /dev/null and b/Examples/UART/UART-Send/UnderstandingUART.jpg differ diff --git a/Examples/external_interrupt/external_interrupt.ino b/Examples/external_interrupt/external_interrupt.ino deleted file mode 100644 index 3c92df4..0000000 --- a/Examples/external_interrupt/external_interrupt.ino +++ /dev/null @@ -1,47 +0,0 @@ -#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); -} diff --git a/Examples/external_interrupt/external_interrupt.png b/Examples/external_interrupt/external_interrupt.png deleted file mode 100644 index 2d29e5c..0000000 Binary files a/Examples/external_interrupt/external_interrupt.png and /dev/null differ diff --git a/Examples/external_interrupt/tinkercad_link.txt b/Examples/external_interrupt/tinkercad_link.txt deleted file mode 100644 index 5ba87ee..0000000 --- a/Examples/external_interrupt/tinkercad_link.txt +++ /dev/null @@ -1 +0,0 @@ -https://www.tinkercad.com/things/b8qUgr1Egv0 diff --git a/Examples/interrupts/EXTI0_Register_Demo/EXTI0_Register_Demo.ino b/Examples/interrupts/EXTI0_Register_Demo/EXTI0_Register_Demo.ino new file mode 100644 index 0000000..b5a762d --- /dev/null +++ b/Examples/interrupts/EXTI0_Register_Demo/EXTI0_Register_Demo.ino @@ -0,0 +1,33 @@ +#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 +} diff --git a/Examples/interrupts/EXTI_Demo/EXTI_Demo.ino b/Examples/interrupts/EXTI_Demo/EXTI_Demo.ino new file mode 100644 index 0000000..6433026 --- /dev/null +++ b/Examples/interrupts/EXTI_Demo/EXTI_Demo.ino @@ -0,0 +1,30 @@ +#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)); +} diff --git a/Examples/interrupts/external_interrupt/external_interrupt.ino b/Examples/interrupts/external_interrupt/external_interrupt.ino new file mode 100644 index 0000000..3c92df4 --- /dev/null +++ b/Examples/interrupts/external_interrupt/external_interrupt.ino @@ -0,0 +1,47 @@ +#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); +} diff --git a/Examples/interrupts/external_interrupt/external_interrupt.png b/Examples/interrupts/external_interrupt/external_interrupt.png new file mode 100644 index 0000000..2d29e5c Binary files /dev/null and b/Examples/interrupts/external_interrupt/external_interrupt.png differ diff --git a/Examples/interrupts/external_interrupt/tinkercad_link.txt b/Examples/interrupts/external_interrupt/tinkercad_link.txt new file mode 100644 index 0000000..5ba87ee --- /dev/null +++ b/Examples/interrupts/external_interrupt/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/b8qUgr1Egv0 diff --git a/Examples/interrupts/pin_change_demo/pin_change_demo.ino b/Examples/interrupts/pin_change_demo/pin_change_demo.ino new file mode 100644 index 0000000..db5f18a --- /dev/null +++ b/Examples/interrupts/pin_change_demo/pin_change_demo.ino @@ -0,0 +1,27 @@ +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; +} diff --git a/Examples/motors/DC_motor_and_servo/DC_motor_and_servo.ino b/Examples/motors/DC_motor_and_servo/DC_motor_and_servo.ino new file mode 100644 index 0000000..8f1c9a1 --- /dev/null +++ b/Examples/motors/DC_motor_and_servo/DC_motor_and_servo.ino @@ -0,0 +1,98 @@ +#include + +#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); +} diff --git a/Examples/motors/DC_motor_and_servo/DC_motor_and_servo.png b/Examples/motors/DC_motor_and_servo/DC_motor_and_servo.png new file mode 100644 index 0000000..d3e4059 Binary files /dev/null and b/Examples/motors/DC_motor_and_servo/DC_motor_and_servo.png differ diff --git a/Examples/motors/DC_motor_and_servo/L293D_example_schematic_with_two_DC_motors.png b/Examples/motors/DC_motor_and_servo/L293D_example_schematic_with_two_DC_motors.png new file mode 100644 index 0000000..68b04aa Binary files /dev/null and b/Examples/motors/DC_motor_and_servo/L293D_example_schematic_with_two_DC_motors.png differ diff --git a/Examples/motors/DC_motor_and_servo/tinkercad_link.txt b/Examples/motors/DC_motor_and_servo/tinkercad_link.txt new file mode 100644 index 0000000..73e9207 --- /dev/null +++ b/Examples/motors/DC_motor_and_servo/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/8ef4pvh4R76 diff --git a/Examples/motors/DC_motor_speed_control/DC_motor_speed_control.ino b/Examples/motors/DC_motor_speed_control/DC_motor_speed_control.ino new file mode 100644 index 0000000..086bee0 --- /dev/null +++ b/Examples/motors/DC_motor_speed_control/DC_motor_speed_control.ino @@ -0,0 +1,21 @@ +#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); +} diff --git a/Examples/motors/DC_motor_speed_control/DC_motor_speed_control.png b/Examples/motors/DC_motor_speed_control/DC_motor_speed_control.png new file mode 100644 index 0000000..c8eb609 Binary files /dev/null and b/Examples/motors/DC_motor_speed_control/DC_motor_speed_control.png differ diff --git a/Examples/motors/DC_motor_speed_control/tinkercad_link.txt b/Examples/motors/DC_motor_speed_control/tinkercad_link.txt new file mode 100644 index 0000000..188b34e --- /dev/null +++ b/Examples/motors/DC_motor_speed_control/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/3tiT8HWMh1X-dcmotorspeedcontrol diff --git a/Examples/motors/Stepper_demo/Backup Of Stepper_demo.pdsbak b/Examples/motors/Stepper_demo/Backup Of Stepper_demo.pdsbak new file mode 100644 index 0000000..6ba6106 Binary files /dev/null and b/Examples/motors/Stepper_demo/Backup Of Stepper_demo.pdsbak differ diff --git a/Examples/motors/Stepper_demo/Drive.png b/Examples/motors/Stepper_demo/Drive.png new file mode 100644 index 0000000..8c3a0a3 Binary files /dev/null and b/Examples/motors/Stepper_demo/Drive.png differ diff --git a/Examples/motors/Stepper_demo/Last Loaded Stepper_demo.pdsbak b/Examples/motors/Stepper_demo/Last Loaded Stepper_demo.pdsbak new file mode 100644 index 0000000..5d39a8f Binary files /dev/null and b/Examples/motors/Stepper_demo/Last Loaded Stepper_demo.pdsbak differ diff --git a/Examples/motors/Stepper_demo/Stepper_demo.PDF b/Examples/motors/Stepper_demo/Stepper_demo.PDF new file mode 100644 index 0000000..101ca36 Binary files /dev/null and b/Examples/motors/Stepper_demo/Stepper_demo.PDF differ diff --git a/Examples/motors/Stepper_demo/Stepper_demo.pdsprj b/Examples/motors/Stepper_demo/Stepper_demo.pdsprj new file mode 100644 index 0000000..d0b5607 Binary files /dev/null and b/Examples/motors/Stepper_demo/Stepper_demo.pdsprj differ diff --git a/Examples/motors/Stepper_demo/Stepper_demo.pdsprj.DESKTOP-Q6QBCIN.Cartogan.workspace b/Examples/motors/Stepper_demo/Stepper_demo.pdsprj.DESKTOP-Q6QBCIN.Cartogan.workspace new file mode 100644 index 0000000..b54f9c5 --- /dev/null +++ b/Examples/motors/Stepper_demo/Stepper_demo.pdsprj.DESKTOP-Q6QBCIN.Cartogan.workspace @@ -0,0 +1,127 @@ + + + + 2c0000000000000001000000ffffffffffffffffffffffffffffffff670000001a000000de06000010040000 + + + + + + + 524 + No + 107 + 100 + + + + + 87 + No + Yes + 87 + Yes + No + No + Yes + 0 + 87 + 100 + 87 + 0 + + + + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000000 + + + + + 2 + Yes + 2 + Yes + Yes + 00000100 + + + + + 2 + Yes + 2 + Yes + Yes + 00000020 + + + + + No + Yes + No + No + Yes + No + 0 + + + + + 636 + No + Yes + 636 + Yes + Yes + No + No + No + 0 + 636 + 100 + 0 + + + + + diff --git a/Examples/motors/Stepper_demo/bipolar-vs-unipolar-stepper-motors.gif b/Examples/motors/Stepper_demo/bipolar-vs-unipolar-stepper-motors.gif new file mode 100644 index 0000000..a13be32 Binary files /dev/null and b/Examples/motors/Stepper_demo/bipolar-vs-unipolar-stepper-motors.gif differ diff --git a/Examples/motors/Stepper_demo/stepper_demo_delay/stepper_demo_delay.ino b/Examples/motors/Stepper_demo/stepper_demo_delay/stepper_demo_delay.ino new file mode 100644 index 0000000..b7ee2b0 --- /dev/null +++ b/Examples/motors/Stepper_demo/stepper_demo_delay/stepper_demo_delay.ino @@ -0,0 +1,68 @@ +#include + +#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); +} diff --git a/Examples/motors/Stepper_demo/stepper_demo_timer/stepper_demo_timer.ino b/Examples/motors/Stepper_demo/stepper_demo_timer/stepper_demo_timer.ino new file mode 100644 index 0000000..a4e8741 --- /dev/null +++ b/Examples/motors/Stepper_demo/stepper_demo_timer/stepper_demo_timer.ino @@ -0,0 +1,99 @@ +#include + +#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); +} + diff --git a/Examples/motors/Stepper_demo/stepper_motor.jpg b/Examples/motors/Stepper_demo/stepper_motor.jpg new file mode 100644 index 0000000..b760c51 Binary files /dev/null and b/Examples/motors/Stepper_demo/stepper_motor.jpg differ diff --git a/Examples/motors/Stepper_demo/stepper_motor_animated.gif b/Examples/motors/Stepper_demo/stepper_motor_animated.gif new file mode 100644 index 0000000..e0ec1bb Binary files /dev/null and b/Examples/motors/Stepper_demo/stepper_motor_animated.gif differ diff --git a/Examples/other/Demo_test/Demo_test - Tinkercad - Schematic.png b/Examples/other/Demo_test/Demo_test - Tinkercad - Schematic.png new file mode 100644 index 0000000..c6be61c Binary files /dev/null and b/Examples/other/Demo_test/Demo_test - Tinkercad - Schematic.png differ diff --git a/Examples/other/Demo_test/Demo_test.ino b/Examples/other/Demo_test/Demo_test.ino new file mode 100644 index 0000000..1cd0b33 --- /dev/null +++ b/Examples/other/Demo_test/Demo_test.ino @@ -0,0 +1,72 @@ +#include + +#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++; +} diff --git a/Examples/other/Demo_test/tinkercad_link.txt b/Examples/other/Demo_test/tinkercad_link.txt new file mode 100644 index 0000000..77596f7 --- /dev/null +++ b/Examples/other/Demo_test/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/ffni7S7fML6 diff --git a/Examples/pin_change_demo/pin_change_demo.ino b/Examples/pin_change_demo/pin_change_demo.ino deleted file mode 100644 index db5f18a..0000000 --- a/Examples/pin_change_demo/pin_change_demo.ino +++ /dev/null @@ -1,27 +0,0 @@ -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; -} diff --git a/Examples/timer/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.ino b/Examples/timer/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.ino new file mode 100644 index 0000000..d603aa4 --- /dev/null +++ b/Examples/timer/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.ino @@ -0,0 +1,54 @@ +/* + 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; + } +} diff --git a/Examples/timer/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.png b/Examples/timer/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.png new file mode 100644 index 0000000..bebc3db Binary files /dev/null and b/Examples/timer/Timer_1_COMPA_Toggle_pin_13_at_1Hz/Timer_1_COMPA_Toggle_pin_13_at_1Hz.png differ diff --git a/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.ino b/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.ino new file mode 100644 index 0000000..efa2118 --- /dev/null +++ b/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.ino @@ -0,0 +1,62 @@ +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); +} diff --git a/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.png b/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.png new file mode 100644 index 0000000..c664e27 Binary files /dev/null and b/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/Timer_1_COMPA_and_OVF_10kHz_PWM.png differ diff --git a/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/tinkercad_link.txt b/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/tinkercad_link.txt new file mode 100644 index 0000000..a0b579d --- /dev/null +++ b/Examples/timer/Timer_1_COMPA_and_OVF_10kHz_PWM/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/c8JLkjplQKy diff --git a/Examples/timer/Timer_1_CompMatchA_Interrupt/Timer_1_CompMatchA_Interrupt.ino b/Examples/timer/Timer_1_CompMatchA_Interrupt/Timer_1_CompMatchA_Interrupt.ino new file mode 100644 index 0000000..99a5bfc --- /dev/null +++ b/Examples/timer/Timer_1_CompMatchA_Interrupt/Timer_1_CompMatchA_Interrupt.ino @@ -0,0 +1,52 @@ +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() +{ + +} diff --git a/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.ino b/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.ino new file mode 100644 index 0000000..e6bb3ef --- /dev/null +++ b/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.ino @@ -0,0 +1,61 @@ +#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); + } +} diff --git a/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.png b/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.png new file mode 100644 index 0000000..fc72730 Binary files /dev/null and b/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable.png differ diff --git a/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/tinkercad_link.txt b/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/tinkercad_link.txt new file mode 100644 index 0000000..aa75c78 --- /dev/null +++ b/Examples/timer/Timer_1_OC1A_Blink_pin_9_at_1Hz_with_external_enable/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/abCdiMvkJs6 diff --git a/Examples/timer/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.ino b/Examples/timer/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.ino new file mode 100644 index 0000000..4f1e4b7 --- /dev/null +++ b/Examples/timer/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.ino @@ -0,0 +1,73 @@ +#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; + } +} diff --git a/Examples/timer/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.png b/Examples/timer/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.png new file mode 100644 index 0000000..31a4373 Binary files /dev/null and b/Examples/timer/Timer_DIP_switch_frequency/Timer_DIP_switch_frequency.png differ diff --git a/Examples/timer/Timer_DIP_switch_frequency/tinkercad_link.txt b/Examples/timer/Timer_DIP_switch_frequency/tinkercad_link.txt new file mode 100644 index 0000000..0095544 --- /dev/null +++ b/Examples/timer/Timer_DIP_switch_frequency/tinkercad_link.txt @@ -0,0 +1 @@ + https://www.tinkercad.com/things/2g5g32R3Fb7 diff --git a/Examples/timer/Timer_PWM_10kHz_D25/Timer_PWM_10kHz_D25.ino b/Examples/timer/Timer_PWM_10kHz_D25/Timer_PWM_10kHz_D25.ino new file mode 100644 index 0000000..636d6cc --- /dev/null +++ b/Examples/timer/Timer_PWM_10kHz_D25/Timer_PWM_10kHz_D25.ino @@ -0,0 +1,23 @@ +// 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() { + +} diff --git a/Examples/timer/Timer_PWM_10kHz_D50/Timer_PWM_10kHz_D50.ino b/Examples/timer/Timer_PWM_10kHz_D50/Timer_PWM_10kHz_D50.ino new file mode 100644 index 0000000..6b60731 --- /dev/null +++ b/Examples/timer/Timer_PWM_10kHz_D50/Timer_PWM_10kHz_D50.ino @@ -0,0 +1,23 @@ +// 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() { + +} diff --git a/Examples/timer/Timer_PWM_2Hz_D25/Timer_PWM_2Hz_D25.ino b/Examples/timer/Timer_PWM_2Hz_D25/Timer_PWM_2Hz_D25.ino new file mode 100644 index 0000000..ca156da --- /dev/null +++ b/Examples/timer/Timer_PWM_2Hz_D25/Timer_PWM_2Hz_D25.ino @@ -0,0 +1,23 @@ +// 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() { + +} diff --git a/Examples/timer/Timer_PWM_2Hz_D80/Timer_PWM_2Hz_D80.ino b/Examples/timer/Timer_PWM_2Hz_D80/Timer_PWM_2Hz_D80.ino new file mode 100644 index 0000000..4698a58 --- /dev/null +++ b/Examples/timer/Timer_PWM_2Hz_D80/Timer_PWM_2Hz_D80.ino @@ -0,0 +1,23 @@ +// 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() { + +}