Arduino Tutorial 44: Understanding Logical Shift Left and Logical Shift Right with the 74HC595

preview_player
Показать описание
You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:

In this lesson we look at the concept of Logical Shift Left and Logical Shift Right on an 8 bit Byte. We show how to do these functions with a 74CH595 connected to an Arduino

You can get the kit I am using for this series at the following link:

Follow these lessons on our Free WEB site:

#Arduino
Рекомендации по теме
Комментарии
Автор

I was able to figure it out by looking at the chart you drew on a previous video & tracking the rows with just 1 bit on. I saw that each time (1, 2, 4, 8...), you could just multiply or divide by 2 to reach the next step so I tried it in my code and it worked! I'm often guilty of over-thinking so these assignments are helping me to try and reign that in some. So often, the answer is simpler than I thought!

HeatherJordanJewelry
Автор

After I did this homework, I used the 595 and what you've taught me so far to create a little game 🎮 The 595 lights up a single LED at a time, starting a loop at 0x01, through to 0xF0, and back to 0x01. I used a green LED at 0xF0; the aim of the game is to use a push button to hit the green LED. When successful, the serial monitor displays the cumulative score. On a miss hit, the track resets. I set threshold score values to reduce the loop delay time, making the lights zoom up and down the track at increasing speed. A fun and practical use of this chip has really helped consolidate my learning so far.

thomasshaw
Автор

No I used the >> operator to right shift and the << operator to left shift. Looking forward to the circular shift. Thanks Paul.

opalprestonshirley
Автор

I made a "shifter" first to the left and then to the right, and restarting again. One problem I encountered was that in the shift to the left, the number got soon two big to be in an int type and then all sorts of crazy things happen. I had to declare the variable as an unsigned int. I leave my code here:
int latchPin = 11;
int clockPin = 9;
int dataPin = 12;

byte LEDs=0b11011011;

int dt = 500;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

unsigned int goShift = LEDs;

// start lights
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, goShift);
digitalWrite(latchPin, HIGH);
delay(dt);

// shift ligts to the left
for (int i = 0; i < 8; i++){
goShift = goShift * 2;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, goShift);
digitalWrite(latchPin, HIGH);
delay(dt);
}

goShift = LEDs;

// shift lights to the right
for (int i = 0; i < 8; i++){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, goShift);
digitalWrite(latchPin, HIGH);
goShift = goShift / 2;
delay(dt);
}

goShift = 0;

// lights off
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, goShift);
digitalWrite(latchPin, HIGH);
delay(dt);

}

ABSP
Автор

Prof., I am sharing your videos with even family members!
Gosh... I wish I had you as a professor in my college years...

daniellehwing
Автор

and completed homework for this great lesson. I misunderstood the "shift" and did a circular bit shift already. Thanks for this lesson in this legendary and most epic Arduino series!

jabber
Автор

done these Arduino lessons so far (brilliant). Also started on the 9 axis but decided learning Python at the same time would explode my brain. However I am now using the 9 axis Arduino stuff along with the Arduino lessons to make a pitch, yaw & roll meter using the 74hc595 displaying bargraph LEDs to show levels off flat. Going to use that in my RV to pitch it flat.. Guess that's the beauty of your teaching methods - we learn to think and apply. Looking forward to the rest of the lessons.

GYTC
Автор

Managed to get the task sorted out. I sat and worked out the decimal numbers and then noticed the relationship. Thinking about it afterwards it made sense! This is a great way to learn this stuff by being pointed in a direction and then figuring it out for ones self.

waynenicolson
Автор

Thanks for the lesson, I did the project, and combined both the logical shift left, and right, in one program.

scrappybobbarker
Автор

I DID IT!! That assignment at the end stumped me and I had to play around with the code for so long to get it to work! Turns out I basically had it from the start, but I tried to do everything in one line, which messed everything up! I came so close to caving and relying on the next lesson's explanation. I'm glad to have stuck it through because I knew I was onto something, and that it would most-likely end up being easier than I initially thought!

FF
Автор

Hi Paul. I want to remind you that people are still learning from your most excellent Arduino tutorials. This lesson was pretty easy. I tried it successfully with both divide/multiply and the >> and << operators. Keep up the great tutorials!

cbrombaugh
Автор

It reminds me of coding back in the 80's in the 640k XT class computers. When you're limited to an 8 bit bus but had graphics adapters which were using 64, 128, 256 colors, you had to serialize the data for the adapter to convert in much the same way. Multiplexing wasn't it? Bit masking, shifting.. writing directly to the screen position in memory as fast as your computers clock could go. Ahh! It's all coming back! 😅

tvtoms
Автор

I figure it out. I multiplied and divided it by 0b10 which is decimal 2. Thanks, Paul for your very very interesting class.

tanvirahmed
Автор

Paul, finally  found solution for an assignment after a few days. Tried not to complicate programming andlook forward  to see lesson 45 to compare your and  my script. Anyway,  it great for me  to follow your lessons. As I am always you are my favorite tutor.

ilyashick
Автор

I did mine with the long code but I at the very start I already got the feeling that there must be a way to do it shorter.
And I observed the decimal-equivalents of the byte and the pattern is there.

I was thrown off about the logical shift left pattern, the thing is... it doesn't look like it has a pattern at first glance.
But after watching this lesson, I figured that because the range of 8-bit binary is from 0 to 255 only...after 255, it comes back to counting from 0.

Thank you for this lesson Granpaul :)

Hino_
Автор

Hello Paul. I did it on my own. Thanks for the great lessons. I like the way you explain these subjects.

remcokoning
Автор

Very Easy to do sir, it just needed a few changes in the code, Thank you again for your teaching.

santiagoperaza
Автор

Homework: myHex=(myHex*2)+(myHex/128). Paul I have binged on videos 1 to 44 in 2 weeks; very much enjoying. Now will have to wait a week for next one, but well worth it.

briantube
Автор

Hello again! I figured out the two homework assignments right before falling asleep last night. I was trying to do the binary counting in my head, so I couldn't be sure until I actually saw it in the code. Decimal 170 was every other LED starting on the right. Decimal 85 was the next four LEDs in the sequence. Just multiplying (and then dividing for the 2nd part) each number by 2 was simple and easy. Thanks again for the brain challenge! At 63, I need all of those I can get. ;-)

charlielowell
Автор

Hello Paul. I found the same solution for the last week assignment and the actual homework is also done. Thanks for Your teaching. It is always a pleasure to watch Your videos. Keep on going.

GeoGebweiler