From d1b34a4a192d34082e800b7bc3fe46f8fe273f3f Mon Sep 17 00:00:00 2001 From: Tom Nordal Date: Sun, 23 Jun 2024 18:22:18 +0200 Subject: [PATCH] Lesson 44 --- ShiftRegLeds/lessons/lesson43.cpp | 37 +++++++++++++++++++++++++++++++ ShiftRegLeds/src/main.cpp | 20 +++++++---------- 2 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 ShiftRegLeds/lessons/lesson43.cpp diff --git a/ShiftRegLeds/lessons/lesson43.cpp b/ShiftRegLeds/lessons/lesson43.cpp new file mode 100644 index 0000000..a42fc76 --- /dev/null +++ b/ShiftRegLeds/lessons/lesson43.cpp @@ -0,0 +1,37 @@ +// https://www.youtube.com/watch?v=FwiKHHUbuLI&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=43 + +#include + +int latchPin = 11; +int clockPin = 9; +int dataPin = 12; + +int dt = 25; +byte LED1s = 0b00000000; +byte LED2s = 0b01010101; + + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + pinMode(latchPin, OUTPUT); + pinMode(clockPin, OUTPUT); + pinMode(dataPin, OUTPUT); + +} + +void loop() { + // put your main code here, to run repeatedly: + digitalWrite(latchPin, LOW); + shiftOut(dataPin, clockPin, LSBFIRST, LED1s); + digitalWrite(latchPin, HIGH); + delay(dt); + + Serial.println(LED1s, BIN); + LED1s++; + + // digitalWrite(latchPin, LOW); + // shiftOut(dataPin, clockPin, LSBFIRST, LED2s); + // digitalWrite(latchPin, HIGH); + // delay(dt); +} diff --git a/ShiftRegLeds/src/main.cpp b/ShiftRegLeds/src/main.cpp index a42fc76..6a0112c 100644 --- a/ShiftRegLeds/src/main.cpp +++ b/ShiftRegLeds/src/main.cpp @@ -1,4 +1,4 @@ -// https://www.youtube.com/watch?v=FwiKHHUbuLI&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=43 +// https://www.youtube.com/watch?v=3JDgL9rgVb0&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=44 #include @@ -6,9 +6,8 @@ int latchPin = 11; int clockPin = 9; int dataPin = 12; -int dt = 25; -byte LED1s = 0b00000000; -byte LED2s = 0b01010101; +int dt = 3000; +byte ledByte = 0b10000000; void setup() { @@ -23,15 +22,12 @@ void setup() { void loop() { // put your main code here, to run repeatedly: digitalWrite(latchPin, LOW); - shiftOut(dataPin, clockPin, LSBFIRST, LED1s); + shiftOut(dataPin, clockPin, LSBFIRST, ledByte); digitalWrite(latchPin, HIGH); - delay(dt); - Serial.println(LED1s, BIN); - LED1s++; + Serial.println(ledByte, BIN); + delay(dt); - // digitalWrite(latchPin, LOW); - // shiftOut(dataPin, clockPin, LSBFIRST, LED2s); - // digitalWrite(latchPin, HIGH); - // delay(dt); + ledByte = ledByte / 2; // Shift right + // ledByte = ledByte * 2; // Shift left }