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.