Hi Folks
Right now my main goal is to try to write sketch using uint8_t and byte patterns.
I don't know what I'm doing exactly Ive just been searching and going over many of other peoples code and honestly a lot of it tends to lose me when the code is written different ways to do the same thing but not explained why one way over the other.
I'm using a 74hc595 register and controlling 32 leds.
I would like to figure out how to properly use an array with the register but this part goes over my head as of now.
Mostly if i would like to program a switch in the circuit and want the switch turn on and off
the LEDs am I doing right so far?
So far this is my code;
uint8_t dataPin = 2;// pin 2 DS - serial data input
uint8_t clockPin = 3; // pin 3 SHCP - shift register clock input
uint8_t latchPin = 4; // pin 4STCP - storage register clock input
uint8_t potPin = A0; // potentiometer is in analog pin 0
uint8_t switchPin= 8; // switch is in pin 8
uint8_t switchState = 0;
uint8_t delayLED; // time delayed between led changes
uint8_t direction = 1;
uint8_t currentLED = 0;
uint8_t val = 0;
unsigned long changeTime;
uint8_t ledState = 0; // state of led
const uint8_t ON = HIGH;
const uint8_t OFF = LOW;
void setup() {
delay(500);
pinMode(dataPin,OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(switchPin, INPUT);
pinMode(potPin, INPUT);
changeTime = millis();
delay(500);
}
void loop()
{
switchPin = digitalRead(switchState);
if(switchState== OFF)
{digitalWrite(switchPin, LOW);}
else{digitalWrite(switchPin, HIGH);}
val = analogRead(potPin);
digitalWrite(dataPin, HIGH);
delay(val);
digitalWrite(dataPin, LOW);
delay(val);
updateLEDs;
}
byte patterns[30] = {
B00000001,(delay),
B00000010,(delay),
B00000100,(delay),
B00001000,(delay),
B00010000,(delay),
B00100000,(delay),
B01000000,(delay),
B10000000,(delay),
B01000000,(delay),
B00100000,(delay),
B00010000,(delay),
B00001000,(delay),
B00000100,(delay),
B00000010,(delay)
};
void updateLEDs(uint8_t val)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, val);
digitalWrite(latchPin, HIGH);
}
I know I have more information to add, i just would like more experienced minds to give my tips or so if i am or not going in the write direction.
Much appreciated for taking the time to read and comment.