Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

// Charlieplexing on an Attiny 85

// Code for making a Larson scanner


// Code by Luc Volders 2016
int pins[] = {0,1,2,3};
int numberpin = 4;
int i;
int delay1 = 110;
int delay2 = 4;
long int start=0;
long int ending=0;
const int ledpins[12][2] ={
// this array contains all connections
// edit the values for your won wiring
{1,0}
,
{0,1}
,
{0,2}
,
{2,0}
,
{0,3}
,
{3,0}
,
{1,2}
,
{2,1}
,
{1,3}
,
{3,1}
,
{2,3}
,
{3,2}
};
void setup()
{
// First we put all leds off
alloff();
delay(3000);
}
void loop()
{
// Larson forward
for(i = 0; i < 12; i++)
{
ledon(i);
delay(delay1);
alloff();
}
// larson backwards
for(i = 11; i >-1 ; i--)
{

ledon(i);
delay(delay1);
alloff();
}
alloff();
}
void alloff()
// This routines puts all leds off
{
for(int i = 0; i < 4; i++)
{
pinMode (pins[i], INPUT);
}
}
void ledon(int lednr)
// This routine puts a led on
{
int pluspin = ledpins[lednr][0];
int negpin = ledpins[lednr][1];
pinMode (pluspin, OUTPUT);
digitalWrite (pluspin, HIGH);
pinMode (negpin, OUTPUT);
digitalWrite (negpin, LOW);
delay(delay2);
}

You might also like