From: vl_garistov Date: Tue, 6 Apr 2021 17:06:14 +0000 (+0300) Subject: Added TinkerCAD links and two new examples - 2 I2C slaves and LCD scrolling texts X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=383c56a722b483a76529a5f18beecc5289547c71;p=vmks.git Added TinkerCAD links and two new examples - 2 I2C slaves and LCD scrolling texts --- diff --git a/Examples/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt b/Examples/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt new file mode 100644 index 0000000..25a297f --- /dev/null +++ b/Examples/3x3-LED_BTN-Matrix-Transpose/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/bJ9mxNp3wXG diff --git a/Examples/7-segm_bidirectional_counter/tinkercad_link.txt b/Examples/7-segm_bidirectional_counter/tinkercad_link.txt new file mode 100644 index 0000000..03bf407 --- /dev/null +++ b/Examples/7-segm_bidirectional_counter/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/kQ6afgEqekR diff --git a/Examples/7-segm_byte_display/7-segm_byte_display.png b/Examples/7-segm_byte_display/7-segm_byte_display.png new file mode 100644 index 0000000..69c7efe Binary files /dev/null and b/Examples/7-segm_byte_display/7-segm_byte_display.png differ diff --git a/Examples/7-segm_byte_display/tinkercad_link.txt b/Examples/7-segm_byte_display/tinkercad_link.txt new file mode 100644 index 0000000..b34ead0 --- /dev/null +++ b/Examples/7-segm_byte_display/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/aHW3wNDugHU diff --git a/Examples/7-segm_driver/tinkercad_link.txt b/Examples/7-segm_driver/tinkercad_link.txt new file mode 100644 index 0000000..db5e83d --- /dev/null +++ b/Examples/7-segm_driver/tinkercad_link.txt @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..075efc3 --- /dev/null +++ b/Examples/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-segm_driver_random/7-segm_driver_random.png b/Examples/7-segm_driver_random/7-segm_driver_random.png new file mode 100644 index 0000000..e23e584 Binary files /dev/null and b/Examples/7-segm_driver_random/7-segm_driver_random.png differ diff --git a/Examples/7-segm_driver_random/tinkercad_link.txt b/Examples/7-segm_driver_random/tinkercad_link.txt new file mode 100644 index 0000000..2d132b6 --- /dev/null +++ b/Examples/7-segm_driver_random/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/3GNvrtWwhQc diff --git a/Examples/7-segm_raw/tinkercad_link.txt b/Examples/7-segm_raw/tinkercad_link.txt new file mode 100644 index 0000000..2e99b79 --- /dev/null +++ b/Examples/7-segm_raw/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/a091SYpyBV8 diff --git a/Examples/7-segm_raw_dynamic/tinkercad_link.txt b/Examples/7-segm_raw_dynamic/tinkercad_link.txt new file mode 100644 index 0000000..c24692b --- /dev/null +++ b/Examples/7-segm_raw_dynamic/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/7eGYywVu5PG diff --git a/Examples/Car_dodge/Car_dodge.ino b/Examples/Car_dodge/Car_dodge.ino index 6925a5e..b9ff517 100644 --- a/Examples/Car_dodge/Car_dodge.ino +++ b/Examples/Car_dodge/Car_dodge.ino @@ -114,6 +114,7 @@ void loop() } // 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) diff --git a/Examples/Car_dodge/tinkercad_link.txt b/Examples/Car_dodge/tinkercad_link.txt new file mode 100644 index 0000000..552eb44 --- /dev/null +++ b/Examples/Car_dodge/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/0J1F6FpWf9y diff --git a/Examples/DC_motor_and_servo/tinkercad_link.txt b/Examples/DC_motor_and_servo/tinkercad_link.txt new file mode 100644 index 0000000..73e9207 --- /dev/null +++ b/Examples/DC_motor_and_servo/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/8ef4pvh4R76 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 new file mode 100644 index 0000000..7fde137 Binary files /dev/null and b/Examples/I2C_2x_interrupt_to_master/I2C_2x_with interrupt_to_master.png 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 new file mode 100644 index 0000000..faf3130 --- /dev/null +++ b/Examples/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_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 new file mode 100644 index 0000000..4beb9d5 --- /dev/null +++ b/Examples/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_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 new file mode 100644 index 0000000..531d888 --- /dev/null +++ b/Examples/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_2x_interrupt_to_master/tinkercad_link.txt b/Examples/I2C_2x_interrupt_to_master/tinkercad_link.txt new file mode 100644 index 0000000..8d653c8 --- /dev/null +++ b/Examples/I2C_2x_interrupt_to_master/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/78jf9y1YodC diff --git a/Examples/I2C_interrupt_to_master/tinkercad_link.txt b/Examples/I2C_interrupt_to_master/tinkercad_link.txt new file mode 100644 index 0000000..ba291d4 --- /dev/null +++ b/Examples/I2C_interrupt_to_master/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/bEpoUSShgaZ diff --git a/Examples/I2C_simple_demo/tinkercad_link.txt b/Examples/I2C_simple_demo/tinkercad_link.txt new file mode 100644 index 0000000..019b53b --- /dev/null +++ b/Examples/I2C_simple_demo/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/b5ZB55WFaxX diff --git a/Examples/LCD_bidirectional_counter/tinkercad_link.txt b/Examples/LCD_bidirectional_counter/tinkercad_link.txt new file mode 100644 index 0000000..1e90ecc --- /dev/null +++ b/Examples/LCD_bidirectional_counter/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/d6absXaO0GD diff --git a/Examples/LCD_scroll/tinkercad_link.txt b/Examples/LCD_scroll/tinkercad_link.txt new file mode 100644 index 0000000..77fb869 --- /dev/null +++ b/Examples/LCD_scroll/tinkercad_link.txt @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..b101089 --- /dev/null +++ b/Examples/LCD_scroll_multiple/LCD_scroll_multiple.ino @@ -0,0 +1,76 @@ +#include +#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 + +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() +{ + 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(200); + 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(200); + LCD_screen.clear(); + } + + delay(500); + } +} + diff --git a/Examples/LCD_scroll_multiple/LCD_scroll_multiple.png b/Examples/LCD_scroll_multiple/LCD_scroll_multiple.png new file mode 100644 index 0000000..74180c4 Binary files /dev/null and b/Examples/LCD_scroll_multiple/LCD_scroll_multiple.png differ diff --git a/Examples/LCD_scroll_multiple/tinkercad_link.txt b/Examples/LCD_scroll_multiple/tinkercad_link.txt new file mode 100644 index 0000000..2770292 --- /dev/null +++ b/Examples/LCD_scroll_multiple/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/des9SoAMtAC diff --git a/Examples/TUES-LED_strip_1/tinkercad_link.txt b/Examples/TUES-LED_strip_1/tinkercad_link.txt new file mode 100644 index 0000000..e186c83 --- /dev/null +++ b/Examples/TUES-LED_strip_1/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/4uzv4lu12yT 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 new file mode 100644 index 0000000..a0b579d --- /dev/null +++ b/Examples/Timer_1_COMPA_and_OVF_10kHz_PWM/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/c8JLkjplQKy 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 new file mode 100644 index 0000000..aa75c78 --- /dev/null +++ b/Examples/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/external_interrupt/tinkercad_link.txt b/Examples/external_interrupt/tinkercad_link.txt new file mode 100644 index 0000000..5ba87ee --- /dev/null +++ b/Examples/external_interrupt/tinkercad_link.txt @@ -0,0 +1 @@ +https://www.tinkercad.com/things/b8qUgr1Egv0