i have to make a project for school, The electronic roulette.
So the french roulette table counts 37numbers (0-36) so for each number i use a led that i am controlling from my arduino thats controls my shift register but one shift register is not enough, so i am using 5 shift registers in one line. the 595 got a serial output so i connect the first 595 to the arduino the data signal line continues to the next by the serial output. But now my question i only get my 2 first registers work because the arduino software has a limit of maximum 4bytes so i seperated it in 3words ( i could do it in 2words and 1int but just to make the total view easier i used 3).
i think the problem is with seperate the 3 words into 6 registers and then sending them out with the shiftout function. does someone have an idea that might help me all replies are very welcome
(my full software that i have up to now you can see below)
with kind regards,
kjelle
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
int del = 10; //delay
int Randomwaarde;
int thisLed;
void setup() {
Serial.begin(9600);
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
randomSeed(analogRead(3));
Randomwaarde = random(190, 210);
Serial.println(Randomwaarde);
}
void loop() {
for (thisLed = 0; thisLed <= 36; thisLed++) {
if (del <= Randomwaarde) //controleerd de del(de vertraging) met de opgegeven randomwaarde
{
registerWrite(thisLed,HIGH);
delay(del);
}
else
{
int EndLed = thisLed ;
registerWrite(EndLed, HIGH);
delay(10000);
randomSeed(analogRead(3));
Randomwaarde = random(190, 210);
Serial.println(EndLed);
Serial.println(Randomwaarde);
del = 10;
}
}
}
void registerWrite(int whichPin, int whichState)
{
word word1 = 0;
word word2 = 0;
word word3 = 0;
byte registerSix;
byte registerFive;
byte registerFour;
byte registerTree;
byte registerTwo;
byte registerOne;
digitalWrite(latchPin, LOW);
if(whichPin <16)
{
bitWrite(word1, whichPin, whichState);
registerOne = highByte(word1);
registerTwo = lowByte(word1);
shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
}
if(whichPin >=16 && whichPin <=31)
{
bitWrite(word2, whichPin, whichState);
registerTree = highByte(word2);
registerFour = lowByte(word2);
shiftOut(dataPin, clockPin, MSBFIRST, registerFour);
shiftOut(dataPin, clockPin, MSBFIRST, registerTree);
shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
}
if(whichPin >=32 && whichPin <=36)
{
bitWrite(word3, whichPin, whichState);
registerFive = lowByte(word3);
registerSix = highByte(word3);
shiftOut(dataPin, clockPin, MSBFIRST, registerSix);
shiftOut(dataPin, clockPin, MSBFIRST, registerFive);
shiftOut(dataPin, clockPin, MSBFIRST, registerFour);
shiftOut(dataPin, clockPin, MSBFIRST, registerTree);
shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
}
digitalWrite(latchPin, HIGH);
Serial.println(whichPin);
del = del +1;
}