Étape 6: programmation
Ce projet utilise la bibliothèque de spi rapide disponible à: http://code.google.com/p/fastspi/Une vidéo montrant l’éventail complet de capacités est illustrée ci-dessous :
Je l’ai fait rien de spécial à la programmation. Mon code inclut un groupe de variables qui définissent les extrémités des bandes de corriger leur étant coupé haut et désordonnés. C’est le code que j’ai utilisé pour la démo sur la page d’introduction. Il y a beaucoup de choses à améliorer.
#include < FastSPI_LED.h >
#define NUM_LEDS 178
struct CRGB {}
unsigned char b ;
unsigned char r ;
unsigned char g ;
}; Parfois les chipsets câblage dans un tri en arrière de façon
struct CRGB * leds ; struct CRGB {unsigned char r; unsigned char g; unsigned char b;} ;
#define PIN 3
#define SSS 1
#define SSE 25
#define CSS 26
#define CST 46
#define m 47
#define STE 73
#define BTS 74
#define BTE 107
#define TTS 108
#define TTE 137
#define LFS 138
#define LFE 157
#define RFS 158
#define RFE 177
#define sur 500
#define hors 100
Sub lightBar (int s, int e, int del, int off, int r, g int, int b) ;
void bottomTube() ;
void topTube() ;
void seatTube() ;
void chainStay() ;
void seatStay() ;
void leftFork() ;
void rightFork() ;
void clearDisplay() ;
int currentBar = 0 ;
int lastBar = 0 ;
int nextBar = 0 ;
int choix = 0 ;
horloge int = 0 ; dans le sens anti-horaire
void setup()
{
FastSPI_LED.setLeds(NUM_LEDS) ;
FastSPI_LED.setChipset(CFastSPI_LED::SPI_TM1809) ;
FastSPI_LED.setPin(PIN) ;
FastSPI_LED.init() ;
FastSPI_LED.start() ;
LED = (struct CRGB*)FastSPI_LED.getRGBData() ;
}
void loop() {}
Si (currentBar == 0 & & lastBar == 0)
{
lastBar = 4 ;
currentBar = 5 ;
horloge = 0 ; dans le sens anti-horaire
}
{Switch(currentBar)}
cas 1: départ affaire //main
{if(Clock==0)}
nextBar = 2 ;
}
rupture ;
cas 2: départ affaire //main
{if(Clock==0)}
choix = random(2) ;
if(Choice==0)
nextBar = 3 ;
d’autre
nextBar = 4 ;
}
else {}
nextBar = 1 ;
}
rupture ;
case 3: //main affaire début
if(lastBar==2|| lastBar == 4) {}
choix = random(2) ;
if(Choice==0)
nextBar = 1 ;
d’autre
nextBar = 5 ;
}
else {}
choix = random(2) ;
if(Choice==0)
nextBar = 2 ;
d’autre
nextBar = 4 ;
}
rupture ;
cas 4: départ affaire //main
{if(Clock==0)}
choix = random(3) ;
if(Choice==0)
nextBar = 5 ;
d’autre if(choice==2)
nextBar = 6 ;
d’autre
nextBar = 7 ;
}
else {}
choix = random(2) ;
if(Choice==0)
nextBar = 3 ;
d’autre
nextBar = 2 ;
}
rupture ;
cas 5: //main affaire début
{if(Clock==0)}
choix = random(2) ;
if(Choice==0)
nextBar = 1 ;
d’autre
nextBar = 3 ;
}
else {}
choix = random(3) ;
if(Choice==0)
nextBar = 4 ;
d’autre if(choice==2)
nextBar = 6 ;
d’autre
nextBar = 7 ;
}
rupture ;
case 6: //main affaire début
{if(Clock==0)}
nextBar = 7 ;
}
else {}
choix = random(3) ;
if(Choice==0)
nextBar = 4 ;
d’autre if(choice==2)
nextBar = 5 ;
d’autre
nextBar = 7 ;
}
rupture ;
cas 7: //main affaire début
{if(Clock==0)}
choix = random(3) ;
if(Choice==0)
nextBar = 4 ;
d’autre if(choice==2)
nextBar = 5 ;
d’autre
nextBar = 6 ;
}
else {}
nextBar = 6 ;
}
rupture ;
}
Switch(currentBar) {//light currentBar
cas 1: lightBar(SSS,SSE,ON,OFF,50,50,50) ; rupture ;
cas 2: lightBar(CSS,CSE,ON,OFF,50,50,50) ; rupture ;
case 3: lightBar(STS,STE,ON,OFF,50,50,50) ; rupture ;
case 4: lightBar(BTS,BTE,ON,OFF,50,50,50) ; rupture ;
cas 5: lightBar(TTS,TTE,ON,OFF,50,50,50) ; rupture ;
case 6: lightBar(RFS,RFE,ON,OFF,50,50,50) ; rupture ;
cas 7: lightBar(LFS,LFE,ON,OFF,50,50,50) ; rupture ;
}
lastBar = currentBar ;
currentBar = nextBar ;
/*
{Switch(lastBar)}
cas 2: départ de //Subcase
choix = random(2) ;
{if(Choice==0)}
nextBar = 3 ;
}
d’autre
nextBar = 5 ;
rupture ; Fin subcase
case 3: début de la //Subcase
nextBar = 2 ;
rupture ; Fin subcase
cas 5: début de la //Subcase
nextBar = 2 ;
rupture ; Fin subcase
}
rupture ; principaux cas fin
cas 5: //main affaire début
{Switch(lastBar)}
cas 1: départ de //Subcase
choix = random(3) ;
{if(Choice==0)}
nextBar = 4 ;
}
else {if(choice==1)
nextBar = 6 ;
}
d’autre
nextBar = 7 ;
rupture ; Fin subcase
case 3: début de la //Subcase
choix = random(3) ;
{if(Choice==0)}
nextBar = 4 ;
}
else {if(choice==1)
nextBar = 6 ;
}
d’autre
nextBar = 7 ;
rupture ; Fin subcase
cas 4: départ de //Subcase
choix = random(2) ;
{if(Choice==0)}
nextBar = 1 ;
}
d’autre
nextBar = 3 ;
rupture ; Fin subcase
case 6: départ de //Subcase
choix = random(2) ;
{if(Choice==0)}
nextBar = 1 ;
}
d’autre
nextBar = 3 ;
rupture ; Fin subcase
cas 7: début de la //Subcase
choix = random(2) ;
{if(Choice==0)}
nextBar = 1 ;
}
d’autre
nextBar = 3 ;
rupture ; Fin subcase
Sub lightBar (int s, int e, int del, int off, int r, g int, int b) {}
pour (int i = s; i < = e; i ++) {}
caviggia LEDs [i] = r ;
les voyants [i] .g = g ;
LEDs [i] .b = b ;
}
FastSPI_LED.show() ;
Delay(del) ;
clearDisplay() ;
Delay(OFF) ;
}
void bottomTube() {}
{
pour (int i = 74; i < = 108; i ++) {}
caviggia LEDs [i] = 50 ;
.g de LEDs [i] = 50 ;
les voyants [i] .b = 50 ;
}
FastSPI_LED.show() ;
}
}
void topTube() {}
{
pour (int i = 108; i < = 140; i ++) {}
caviggia LEDs [i] = 50 ;
.g de LEDs [i] = 50 ;
les voyants [i] .b = 50 ;
}
FastSPI_LED.show() ;
}
}
void seatTube() {}
pour (int i = 48; i < = 74; i ++)
{
caviggia LEDs [i] = 50 ;
.g de LEDs [i] = 50 ;
les voyants [i] .b = 50 ;
}
FastSPI_LED.show() ;
}
void chainStay() {}
{
pour (int i = 22; i < = 47; i ++) {}
caviggia LEDs [i] = 50 ;
.g de LEDs [i] = 50 ;
les voyants [i] .b = 50 ;
}
FastSPI_LED.show() ;
}
}
void seatStay() {}
{
pour (int i = 1; i < = 22; i ++) {}
caviggia LEDs [i] = 50 ;
.g de LEDs [i] = 50 ;
les voyants [i] .b = 50 ;
}
FastSPI_LED.show() ;
}
}
void leftFork() {}
{
pour (int i = 159; i < = 178; i ++) {}
caviggia LEDs [i] = 50 ;
.g de LEDs [i] = 50 ;
les voyants [i] .b = 50 ;
}
FastSPI_LED.show() ;
}
}
void rightFork() {}
{
pour (int i = 140; i < = 159; i ++) {}
caviggia LEDs [i] = 50 ;
.g de LEDs [i] = 50 ;
les voyants [i] .b = 50 ;
}
FastSPI_LED.show() ;
}
}
void clearDisplay() {}
{
pour (int i = 0; i < = 177; i ++) {}
caviggia LEDs [i] = 0 ;
.g de LEDs [i] = 0 ;
.b LEDs [i] = 0 ;
}
FastSPI_LED.show() ;
}
}
Informations non essentielles sur le code
Le programme que j’ai ici est juste une pleine barre simultanément en cours d’exécution et changeant à un bar adjacent dans le sens de la marche. Par exemple, la première barre pourrait être le séjour de siège, le second peut alors être soit le tube horizontal, le tube de selle ou de la chaîne rester comme une direction n’a pas encore été établie. Dire que le tube supérieur était la seconde barre. Un sens de la marche a été mis en place et la troisième barre peut être le tube inférieur ou une des fourchettes. Le bar lumineux se poursuit ensuite avec impatience jamais doubler sur lui-même.