Currently I am trying to build a step sequencer with 16 steps. I wanted to have 16 LEDs which light up one after another, just like at a normal step sequencer. I already had a code written for getting analog Inputs but now I would like to send digital signal in order to light up the LEDs individually. Right now, the row 1 to 8 and 9 to 19 light up one after another independently, but I want all the 16 LEDs to light up LED by LED. I thank you in advance!
The "for" loop goes 0 to 7 with i and at each step illuminates LED i and i + 8. So lighting 0 and 8, 1 and 9, &c.
Seems like an easy change to make a loop that goes across all 16… and light just i at each step.
Try to understand the code you have. If you wrote it, you should be able to change it easily. If you didn't write it, try to understand the code you have.
Take a close look at the code you have and try to figure out how it works.
I don't really understand the way how the Teensy "tells" the multiplexers which pin they should turn on in order to light up the LED. Also alto777 I'm sorry, the code I posted doesn't work. The one which kinda works is this one:
int pin_Out_S0 = 0;
int pin_Out_S1 = 1;
int pin_Out_S2 = 2;
int LEDState[32];
int bit1 = 0;
int bit2 = 0;
int bit3 = 0;
void LEDsteuern(int, int);
void setup() {
//Select-Pins
pinMode(pin_Out_S0, OUTPUT);
pinMode(pin_Out_S1, OUTPUT);
pinMode(pin_Out_S2, OUTPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
Serial.begin(9600);
}
void loop() {
for (int i {0}; i < 8; ++i)
{
bit1 = bitRead(i, 0);
bit2 = bitRead(i, 1);
bit3 = bitRead(i, 2);
digitalWrite(pin_Out_S0, bit1);
digitalWrite(pin_Out_S1, bit2);
digitalWrite(pin_Out_S2, bit3);
digitalWrite(14, HIGH);
digitalWrite(15, HIGH);
delay(80);
}
}
void LEDsteuern (int zaehler, int digitalPin)
{
digitalWrite(zaehler, HIGH);
}
This one is turning on the 1st and 9th one, then 2nd and 10th, 3rd and 11th and so on... I want them to light up step by step from 1 to 16.
No sign of that in the code you posted. Once anything that serves no purpose is removed, it's a simple program.
Show us the problem you are having in the context of the hardware you are attempting to use. Assuming you really would have no trouble fixing the program you did post, no doubt your problems come from trying to deal also with your multiplexers.
Since the CD74HC4051E Multiplexers share the same control pins, the only way you decide what goes out is by setting the copy pin to HIGH or LOW and repeat the loop
As you use PWM pins (14 and 15 - A0 and A1 on Teensy 4.0) you can also use analogWrite() instead of digitalWrite() for those 2 pins (not the S0,S1,S2 pins) to set a PWM signal and you can control the intensity of the LED
You are right, the problem is probably the sequence how I connected the LEDs. I will check them again and add the resistors. Could you maybe explain the math behind the reason why I have to pick a resistor between 220 to 330 Ohm?
a LED draws as much current as it can from its source and depending on the LED color/build also has a Forward Voltage.
You want a small enough current flowing through your Arduino pins, I thin the teensy will start suffering if you go above 25mA. You have a know voltage "U" when you put your pin HIGH on your teensy and you have a resistor in series with the LED.
So you use the infamous U = RI rule to find R based on the Forward Voltage from the LED and I, the current you want.
My rule of thumb is something between 220 and 330 should be good enough for most cases with 3.3 or 5V Arduinos and common LEDs. The higher the resistance, the lower the current. So if you want to play safe, go for higher - but not too high or the LED won't light on as it needs enough current. Most LED would light up at 5mA probably those days
R = (V(source) - V(led)) / I(led)
V(source) is the source voltage, measured in volts (V),
V(led) is the voltage drop across the LED, measured in volts (V),
I(led) is the current through the LED, measured in Amperes (Amps/A), and
R is the resistance, measured in Ohms (Ω).
if you don't want to do the math, there are online tools