Go Down

Topic: shift register (Read 660 times) previous topic - next topic

kl

bonjour ,
je suis nouveau donc je voulais savoir si quelqu'un pouvait m'aider car je n'arrive pas à très bien comprendre le fonctionnement du shift register , la j'ai un programme ou j'ai pas compris pourquoi il appelle
latchPin ou encore dataPin et ClockPin ? et shiftOut il sert à quoi
merci de bien vouloir me renseigner
merci :-) ;)

//Pin connected to Pin 12 of 74HC595 (Latch)
int latchPin = 8;
//Pin connected to Pin 11 of 74HC595 (Clock)
int clockPin = 12;
//Pin connected to Pin 14 of 74HC595 (Data)
int dataPin = 11;
void setup() {
//set pins to output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
//count from 0 to 255
for (int i = 0; i < 256; i++) {
//set latchPin low to allow data flow
digitalWrite(latchPin, LOW);
shiftOut(i);
//set latchPin to high to lock and send data
digitalWrite(latchPin, HIGH);
delay(500);
}
}
void shiftOut(byte dataOut) {
// Shift out 8 bits LSB first,
// on rising edge of clock
boolean pinState;
//clear shift register ready for
sending data
digitalWrite(dataPin, LOW);
digitalWrite(clockPin, LOW);
// for each bit in dataOut send out
a bit
for (int i=0; i<=7; i++) {
//set clockPin to LOW prior to sending bit
digitalWrite(clockPin, LOW);
// if the value of DataOut and (logical
AND) a bitmask
// are true, set pinState to 1 (HIGH)
if ( dataOut & (1<<i) ) {
pinState = HIGH;
}
else {!
pinState = LOW;
}
//sets dataPin to HIGH or LOW depending on
pinState
digitalWrite(dataPin, pinState);
//send bit out on rising edge of clock
digitalWrite(clockPin, HIGH);
}
//stop shifting out data
digitalWrite(clockPin, LOW);
}

flaith


kl

merci bcp de ta réponse rapide , mais je ne comprends pas pourquoi il faut utiliser le calcul binaire ???????????? :-[

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy