summaryrefslogtreecommitdiffstats
path: root/LoLShield/Examples/charli_heart/applet/charli_heart.cpp
blob: 4d227cc0857cab60d2d63df3d3f107de6b9c7d27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
  Example for Charliplexing library
  
  Alex Wenger <a.wenger@gmx.de> http://arduinobuch.wordpress.com/

  History:
  	30/Dez/09 - V0.0 wrote the first version at 26C3/Berlin

*/
#include "Charliplexing.h"

#include "WProgram.h"
void setup();
void heart();
void loop();
struct point {
  uint8_t xp;        // Point Position in X direction (multplied by 16)
  uint8_t x_speed;   // Speed
  uint8_t flag;  
} points[9];

void setup()                    // run once, when the sketch starts
{
  LedSign::Init();
  
  for(uint8_t i = 0; i < 9; i++)
  {
    points[i].xp = 0;
    points[i].x_speed = random(1, 16);
    points[i].flag = 1;
  }
}

uint8_t heart_p[] = {
  4,5,
  3,4,
  2,4,
  5,4,
  6,4,
  7,5,
  1,5,
  7,6,
  1,6,
  6,7,
  2,7,
  5,8,
  3,8,
  4,9,
};

void heart()
{
  for(uint8_t y = 0; y < 9; y++)
    for(uint8_t x = 3; x < 11; x++)
    {
      LedSign::Set(x,y,0);    
    }
  for(uint8_t i = 0; i < 14; i++)
  {
    LedSign::Set(heart_p[i*2+1],heart_p[i*2],1);    
  }
}

uint8_t heart_flag;

void loop()                     // run over and over again
{
  for(uint8_t i = 0; i < 9; i++)
  {
    points[i].xp += points[i].x_speed;
    if (points[i].xp >= 14*16) 
    {
      points[i].x_speed = random(1, 16);
      points[i].xp = 0;
      points[i].flag ^= 1;
    }
    LedSign::Set(points[i].xp/16,i,points[i].flag);    
  }
  
  heart_flag++;
  if (heart_flag < 20) {
    heart();
  }
  
  delay(40);
}

int main(void)
{
	init();

	setup();
    
	for (;;)
		loop();
        
	return 0;
}