Help me program the taillights of a car

Hello.
I had Ben make a program before, and I’ve been studying various things based on it, but it’s still difficult, so can you help me?

The program that Ben taught me is:

var parkingPin = 5
var brakePin = 4
var turnPin = 16;

var blinkerDelayMs = 500

var leader = 0
var direction = 0
var pixels = array(pixelCount)
var mode = 0
var lastMode = 0
var modeFns = array(4)
var blinkerTimer = 0

pinMode(parkingPin, INPUT);
pinMode(brakePin, INPUT);
pinMode(turnPin, INPUT);

modeFns[0] = (i) => {} //dark
modeFns[1] = (i) => { hsv(0.05, 1, pixels[i]) } // yellow/orange turn
signal swipe
modeFns[2] = (i) => { hsv(0, 1, 1) } //full red
modeFns[3] = (i) => { hsv(0, 1, 0.3) } // dim red

function getMode() {
 if (digitalRead(turnPin))
   return 1
 else if (digitalRead(brakePin))
   return 2
 else if (digitalRead(parkingPin))
   return 3
 return 0
}

export function beforeRender(delta) {
 var oldLeader = leader;
 leader += direction * 2
 if (leader >= pixelCount) {
   direction = 0
 }

 if (direction != 0) {
   for (i = floor(oldLeader); i <= leader; i++)
     pixels[i] = 1
 }
 mode = getMode()

   //check if binker mode is stopping, set a timer to prevent red
 if (lastMode == 1 && mode != lastMode) {
   blinkerTimer = blinkerDelayMs
 }

 //as long as blinkerTimer is running (and there is no blinker
signal), draw black
 if (blinkerTimer > 0 && mode != 1) {
   blinkerTimer -= delta;
   mode = 0
 }
 lastMode = mode

 if (mode == 1)
   start()
 else
   dark()
}


function start() {
 if (direction != 0)
  return
 direction = 1
 leader = 0

}

function dark() {
 for (i = 0; i < pixelCount; i++) {
   pixels[i] = 0
 }
 direction = 0
}

export function render(index) {
 modeFns[mode](index)
}

In this program, the turn signal is only on one side, so I would like to add a mode that flows in the opposite direction.

If there is an input in GP5, I would like to create a program that flows in the opposite direction of the GP16 program and a program that flows in the center or left and right when GP5 and GP16 are turned on at the same time. Is this possible?

I don’t speak English, so I’m converting with translation software. Please forgive strange sentences.

Hi @kuu_neru,

You might also want to check out this thread:

It was the beginning of where that pattern came from, and might help understand how and why some of the code works.

I hope to come back to this thread and write more later, unless other folks beat me to it and answer you, but wanted to at least get you started!

1 Like

I checked past threads, but couldn’t understand.

This program is a program that flows the turn signal from the beginning to the end, but it cannot be changed to a program that

I’d like to ask you for your help