mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-25 18:14:05 +02:00
tornado/fw/tornado.c: use LED_* to communicate with LED bar; update demo
Instead of a counter, which worked okay with 16 LEDs but is useless with all 64 of them, we now show a filling/emptying bar. The update speed is high enough that rotation results in about a quarter-circle pattern.
This commit is contained in:
parent
53b2df2683
commit
9447541679
@ -17,6 +17,8 @@
|
|||||||
MASK(port, LED_DS) | MASK(port, LED_LCLK) | MASK(port, LED_SCLK))
|
MASK(port, LED_DS) | MASK(port, LED_LCLK) | MASK(port, LED_SCLK))
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @@@ For testing, connect the LED bar via the 8:10 card slot, so that it
|
* @@@ For testing, connect the LED bar via the 8:10 card slot, so that it
|
||||||
* can be disconnected without soldering.
|
* can be disconnected without soldering.
|
||||||
@ -27,19 +29,33 @@
|
|||||||
#define DS CARD_CLK
|
#define DS CARD_CLK
|
||||||
#define VDD CARD_CMD
|
#define VDD CARD_CMD
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
static void send(uint16_t pattern)
|
#define SCLK LED_SCLK
|
||||||
|
#define LCLK LED_LCLK
|
||||||
|
#define DS LED_DS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define N_LEDS 64
|
||||||
|
|
||||||
|
|
||||||
|
static void send(uint8_t pattern[N_LEDS/8])
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i, j, mask;
|
||||||
|
|
||||||
for (i = 0; i != 16; i++) {
|
for (i = 0; i != N_LEDS/8; i++) {
|
||||||
if (pattern & 0x8000)
|
mask = 1;
|
||||||
SET(DS);
|
for (j = 0; j != 8; j++) {
|
||||||
else
|
if (pattern[i] & mask)
|
||||||
CLR(DS);
|
SET(DS);
|
||||||
SET(SCLK);
|
else
|
||||||
CLR(SCLK);
|
CLR(DS);
|
||||||
pattern <<= 1;
|
SET(SCLK);
|
||||||
|
CLR(SCLK);
|
||||||
|
mask <<= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SET(LCLK);
|
SET(LCLK);
|
||||||
CLR(LCLK);
|
CLR(LCLK);
|
||||||
@ -80,8 +96,9 @@ static uint16_t adc(bool x)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
static uint8_t p[N_LEDS/8];
|
||||||
uint8_t mode = 0;
|
uint8_t mode = 0;
|
||||||
uint16_t n = 0;
|
uint16_t n = 0, v;
|
||||||
|
|
||||||
PORTB = HIGH(B);
|
PORTB = HIGH(B);
|
||||||
PORTC = HIGH(C);
|
PORTC = HIGH(C);
|
||||||
@ -97,8 +114,11 @@ int main(void)
|
|||||||
OUT(LCLK);
|
OUT(LCLK);
|
||||||
OUT(DS);
|
OUT(DS);
|
||||||
|
|
||||||
|
#ifdef VDD
|
||||||
SET(VDD);
|
SET(VDD);
|
||||||
OUT(VDD);
|
OUT(VDD);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
while (!PIN(SW_SW));
|
while (!PIN(SW_SW));
|
||||||
@ -110,15 +130,28 @@ int main(void)
|
|||||||
mode = 2;
|
mode = 2;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 1:
|
case 1:
|
||||||
send(adc(0));
|
n = adc(0);
|
||||||
|
p[0] = n;
|
||||||
|
p[1] = n >> 8;
|
||||||
|
p[2] = p[3] = p[4] = p[5] = p[6] = p[7] = 0;
|
||||||
|
send(p);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
send(adc(1));
|
n = adc(1);
|
||||||
|
p[0] = n;
|
||||||
|
p[1] = n >> 8;
|
||||||
|
p[2] = p[3] = p[4] = p[5] = p[6] = p[7] = 0;
|
||||||
|
send(p);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
send(n);
|
v = 63-n;
|
||||||
|
if (n & 64)
|
||||||
|
p[(v >> 3) & 7] &= ~(1 << (v & 7));
|
||||||
|
else
|
||||||
|
p[(v >> 3) & 7] |= 1 << (v & 7);
|
||||||
|
send(p);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
// _delay_ms(100);
|
_delay_ms(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user