I apologise for my lack of code understanding before hand.
I have used some Ardrunio Uno code, from rudysarduinoprojects, to make some model railway sized fire engines lights flash in a realistic way. While using a full sized Ardruino Uni and Maker Uno, the LED’s work perfectly. But in installing the code and using the same pin numbers on the RP2040 only one set of LED’s on my test board light up and they aren’t flashing. Which is wired to pin 8.
I really want to get this tiny board to work, as then I can keep it inside the fire engine, rather than having loads of wired coming out of it. But I bearly understand the code (just enough to change the number of LED’s), also in case you’re wondering, I have 2 and 3x2 led’s on some of the pins, to cut down on the number of wires.
Here’s the code:
#define NUM_LEDS 5
#define NUM_STEPS 48
#define BLINK_SPEED 60 // [ms] lower value = faster blinking
#define BLINK_TIME 60 // [s]
#define TRIGGER_PIN 2
byte led_pin[NUM_LEDS] = {6,7,8,9,10};
byte sequencer[NUM_LEDS][NUM_STEPS] = {
// 0 1 2 3 4
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,
0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,
1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0
};
byte state = 1, transition;
byte n, p, blink_enabled;
unsigned long time_to_change, time_to_switch_off;
void setup() {
pinMode(TRIGGER_PIN, INPUT_PULLUP);
for(n=0; n<NUM_LEDS; n++) {
pinMode(led_pin[n], OUTPUT);
digitalWrite(led_pin[n], LOW);
}
Serial.begin(9600);
Serial.println("Blink sequencer ready, waiting for trigger");
}
void loop() {
switch(state) {
case 1: // idle
if(digitalRead(TRIGGER_PIN) == LOW) transition = 12;
break;
case 2: // blinking for ON_TIME seconds
if(millis() > time_to_switch_off) transition = 21;
break;
}
switch(transition) {
case 12:
blink_enabled = 1;
time_to_switch_off = millis() + (unsigned long)BLINK_TIME * 1000;
Serial.println("Triggered, blinking started");
transition = 0;
state = 2;
break;
case 21:
blink_enabled = 0;
time_to_change = 0;
for(n=0; n<NUM_LEDS; n++)
digitalWrite(led_pin[n], LOW);
Serial.println("Time is up, blinking stopped");
transition = 0;
state = 1;
break;
}
if (blink_enabled) {
if (millis() > time_to_change) {
time_to_change = millis() + (unsigned long)BLINK_SPEED;
for(n=0; n<NUM_LEDS; n++) {
digitalWrite(led_pin[n], sequencer[n][p]);
}
p = (p + 1) % NUM_STEPS;
}
}
}
I’d show you some pictures of how I wired it up, but the forum wont let me embed items, hopefully a link to the pictures on imgur work: Trying to get fire engine lighting to work - Album on Imgur
Here’s a video of what it looks when running on a Maker Uno: https://youtu.be/_Qk9Se5q3hU