forked from ghostrich/microcontroller_haecksen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc3_intro.ino
155 lines (129 loc) · 5.76 KB
/
rc3_intro.ino
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int hCenter = 64; // horizontal center of animation
int vCenter = 16; // vertical center of animation
int Hstar, Vstar; // star location currently
int Quantity = 100; // number of stars
int StarProgress[100]; // array that tracks progress of each star
int StarAngle[100] = {}; // array that tracks angle of each star
int interval[75] = {}; // array used to track speed of each star
//int loops = 0;
const unsigned char rc3logo [] PROGMEM = {
// rc3logo, 32x32px
0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x81, 0xfd, 0xfd, 0xfd,
0x81, 0x85, 0x81, 0x8d, 0x81, 0x85, 0x80, 0x0d, 0x81, 0xfd, 0x80, 0xfd, 0x81, 0xf9, 0x80, 0x05,
0x81, 0x99, 0x81, 0x8d, 0x81, 0x8d, 0xfd, 0xfd, 0x80, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff
};
const unsigned char rocket [] PROGMEM = {
// 'brandy_rockets_2, 14x32px
0x03, 0x00, 0x07, 0x80, 0x1f, 0xc0, 0x3f, 0xf0, 0x3f, 0xf0, 0x78, 0x78, 0x70, 0x38, 0xe0, 0x1c,
0xe0, 0x1c, 0xf0, 0x3c, 0xf8, 0x7c, 0xfc, 0xfc, 0xff, 0xfc, 0xff, 0xfc, 0xff, 0xfc, 0xff, 0xfc,
0xff, 0xfc, 0xff, 0xfc, 0x7f, 0xf8, 0x7f, 0xf0, 0x4f, 0xf0, 0x47, 0xd0, 0xc7, 0x98, 0x87, 0x88,
0x87, 0x88, 0x83, 0x08, 0x83, 0x08, 0x83, 0x18, 0xc3, 0x18, 0x43, 0x10, 0x03, 0x00, 0x03, 0x00
};
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
for (int i = 0; i < Quantity; i++) { // loop to setup initial stars
StarAngle[i] = random(360); // generates random angle for each star
interval[i] = (random(4))+1; // generates random speed for each star +1 keeps stars from being zero
}
display.clearDisplay();
display.display();
display.clearDisplay();
display.drawBitmap(-24, 0, rc3logo, 32, 32, 1);
display.display();
delay(100);
display.clearDisplay();
display.drawBitmap(-12, 0, rc3logo, 32, 32, 1);
display.display();
delay(100);
display.clearDisplay();
display.drawBitmap(0, 0, rc3logo, 32, 32, 1);
display.display();
delay(100);
display.clearDisplay();
display.drawBitmap(12, 0, rc3logo, 32, 32, 1);
display.display();
delay(100);
display.clearDisplay();
display.drawBitmap(24, 0, rc3logo, 32, 32, 1);
display.display();
delay(100);
display.clearDisplay();
display.drawBitmap(36, 0, rc3logo, 32, 32, 1);
display.display();
delay(100);
display.clearDisplay();
display.drawBitmap(48, 0, rc3logo, 32, 32, 1);
display.display();
delay(1000);
display.clearDisplay();
display.drawBitmap(48, -12, rc3logo, 32, 32, 1);
display.display();
delay(100);
display.clearDisplay();
display.drawBitmap(48, -24, rc3logo, 32, 32, 1);
display.display();
delay(100);
display.clearDisplay();
display.drawBitmap(48, -36, rc3logo, 32, 32, 1);
display.display();
delay(1000);
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(20, 10);
display.println(F("haecksen"));
display.display();
delay(3000);
display.clearDisplay();
display.drawBitmap(57, 0, rocket, 14, 32, 1);
display.display();
delay(3000);
for (int loops = 0; loops < 50; loops++) {
unsigned long currentMillis = millis();
display.clearDisplay(); // clear display
for (int i = 0; i < Quantity; i++) { // loop to draw each star
if (StarProgress[i] > 70) { // if statement to reset stars after going off screen
StarProgress[i] = StarProgress[i] - 70; // resets star progress
StarAngle[i] = random(360); // resets star angle
interval[i] = (random(4))+1; // resets star speed
}else{
StarProgress[i] = StarProgress[i] + interval[i]; // distance traveled for star
}
if (currentMillis - StarProgress[i] >= interval[i] && StarProgress[i] > 0) { // if statement to exclude some star paths
Hstar = (hCenter + (sin(StarAngle[i] / 57.296) * StarProgress[i] )); // calculates star horizontal coordinate
Vstar = (vCenter + (cos(StarAngle[i] / 57.296) * StarProgress[i] )); // calculates star horizontal coordinate
display.drawPixel(Hstar, Vstar, SSD1306_WHITE);
}
}
display.display();
delay(100);
Serial.println(loops);
}
display.clearDisplay();
display.display();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(20, 10);
display.println(F("have fun!"));
display.display();
}
void loop() {
}