Skip to content

Instantly share code, notes, and snippets.

@prasertsakd
Created January 13, 2018 08:13
Show Gist options
  • Save prasertsakd/2e3363b669377a0289ef096ea0f8ad75 to your computer and use it in GitHub Desktop.
Save prasertsakd/2e3363b669377a0289ef096ea0f8ad75 to your computer and use it in GitHub Desktop.
tiny13a
int timer = 100;
const PROGMEM unsigned int ledPins[] =
{ 0,1,2,3,4,0,1,2,3,4,
4,3,2,1,0,4,3,2,1,0,
0,1,2,3,4,4,3,2,1,0,
4,3,2,1,0,0,1,2,3,4,};
const PROGMEM unsigned int stepCount = 10;
unsigned int randomloop;
unsigned long m_w = 1;
unsigned long m_z = 2;
void setup() {
for (int thisPin = 0; thisPin < 5; thisPin++) {
pinMode(thisPin, OUTPUT);
}
randomloop = getRandom() %4 -2;
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < randomloop; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[(10*randomloop)+thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[(10*randomloop)+thisPin], LOW);
}
}
unsigned long getRandom()
{
m_z = 36969L * (m_z & 65535L) + (m_z >> 16);
m_w = 18000L * (m_w & 65535L) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment