From b68fbc853f661d539616fde627be91951e0ed741 Mon Sep 17 00:00:00 2001 From: Tom Nordal Date: Mon, 24 Jun 2024 20:11:11 +0200 Subject: [PATCH] Lesson 45 --- ShiftRegLeds/lessons/lesson44.cpp | 33 +++++++++++++++++++++++++++++++ ShiftRegLeds/src/main.cpp | 10 +++++----- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 ShiftRegLeds/lessons/lesson44.cpp diff --git a/ShiftRegLeds/lessons/lesson44.cpp b/ShiftRegLeds/lessons/lesson44.cpp new file mode 100644 index 0000000..6a0112c --- /dev/null +++ b/ShiftRegLeds/lessons/lesson44.cpp @@ -0,0 +1,33 @@ +// https://www.youtube.com/watch?v=3JDgL9rgVb0&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=44 + +#include + +int latchPin = 11; +int clockPin = 9; +int dataPin = 12; + +int dt = 3000; +byte ledByte = 0b10000000; + + +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, ledByte); + digitalWrite(latchPin, HIGH); + + Serial.println(ledByte, BIN); + delay(dt); + + ledByte = ledByte / 2; // Shift right + // ledByte = ledByte * 2; // Shift left +} diff --git a/ShiftRegLeds/src/main.cpp b/ShiftRegLeds/src/main.cpp index 6a0112c..454ffd0 100644 --- a/ShiftRegLeds/src/main.cpp +++ b/ShiftRegLeds/src/main.cpp @@ -1,4 +1,4 @@ -// https://www.youtube.com/watch?v=3JDgL9rgVb0&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=44 +// https://www.youtube.com/watch?v=-WDO4mi2I68&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=45 #include @@ -6,8 +6,8 @@ int latchPin = 11; int clockPin = 9; int dataPin = 12; -int dt = 3000; -byte ledByte = 0b10000000; +int dt = 100; +byte ledByte = 0b11111110; void setup() { @@ -28,6 +28,6 @@ void loop() { Serial.println(ledByte, BIN); delay(dt); - ledByte = ledByte / 2; // Shift right - // ledByte = ledByte * 2; // Shift left + ledByte = ledByte * 128 + ledByte / 2; // Shift right + // ledByte = ledByte / 128 + ledByte * 2; // Shift left }