-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimple-Draw.ino
163 lines (135 loc) · 3.43 KB
/
Simple-Draw.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
156
157
158
159
160
161
162
163
/*
Name: Simple-Draw.ino
Created: 6/25/2016 1:40:21 PM
Author: Slade
*/
// the setup function runs once when you press reset or power the board
#include <Arduboy.h>
int PixX = 0; //Pixel X Position
int PixY = 0; //Pixel Y Position
boolean drawOK= false; //Set a T/F variable to see if the program has started
Arduboy ab; //Declare the Arduboy
void setup() {
ab.setFrameRate(60); //Smooth frame rate.
ab.begin(); //Turn it on without a Logo
txtinit(); //Run the next routine
}
void txtinit() {
ab.clear(); //Clear the screen
ab.setCursor(2, 0); //Set the cursor
ab.print("Simple Draw"); //Write text to the buffer
ab.setCursor(2, 10);
ab.print("By Slade 2016");
ab.setCursor(2, 20);
ab.print("Press A & B to Begin");
ab.setCursor(2, 30);
ab.print("Press A to draw slow");
ab.display(); //Display the buffer
}
// the loop function runs over and over again until power down or reset
void loop() {
if (!(ab.nextFrame())) return; //If not the next frame skip everything.
if (ab.pressed(A_BUTTON + B_BUTTON)) {
PixX = 0; //Set co-ordinates of the X & Y position.
PixY = 0;
drawOK = true; //Set flag to true to start drawing.
ab.clear();
ab.drawPixel(PixX, PixY, WHITE);
ab.display();
}
if (drawOK) { //Check to see if true, if so, allow drawing.
Draw();
}
}
void Draw() {
if (ab.buttonsState() == 0) { //Check to see if no buttons are pressed.
ab.drawPixel(PixX, PixY, WHITE); //Turn the current pixel on
delay(10); //Wait 10ms
ab.display();
ab.drawPixel(PixX, PixY, BLACK); //turn the current pixel off
delay(10);
ab.display();
}
if (ab.pressed(UP_BUTTON)) {
isblackpixel(); //Check to see if the current pixel is off (due to the flashing routine above)
//If so, turn the pixel on, before moving onto the rest of the if/then statement
PixY--; //Subtract 1 from the Y co-ordinate.
ab.drawPixel(PixX, PixY, WHITE);
ab.display();
if (PixY <= 0) { //If we hit the left edge of the screen, don't go any further.
PixY = 0;
}
}
if (ab.pressed(DOWN_BUTTON)) {
isblackpixel();
PixY++;
ab.drawPixel(PixX, PixY, WHITE);
ab.display();
if (PixY >= 63) {
PixY = 63;
}
}
if (ab.pressed(RIGHT_BUTTON)) {
isblackpixel();
PixX++;
ab.drawPixel(PixX, PixY, WHITE);
ab.display();
if (PixX >= 127) {
PixX = 127;
}
}
if (ab.pressed(LEFT_BUTTON)) {
isblackpixel();
PixX--;
ab.drawPixel(PixX, PixY, WHITE);
ab.display();
if (PixX <= 0) {
PixX = 0;
}
}
if (ab.pressed(A_BUTTON + RIGHT_BUTTON)) {
isblackpixel();
PixX++;
ab.drawPixel(PixX, PixY, WHITE);
delay(200);
ab.display();
if (PixX >= 127) {
PixX = 127;
}
}
if (ab.pressed(A_BUTTON + LEFT_BUTTON)) {
isblackpixel();
PixX--;
ab.drawPixel(PixX, PixY, WHITE);
delay(200);
ab.display();
if (PixX <= 0) {
PixX = 0;
}
}
if (ab.pressed(A_BUTTON + UP_BUTTON)) {
isblackpixel();
PixY--;
ab.drawPixel(PixX, PixY, WHITE);
delay(200);
ab.display();
if (PixY <= 0) {
PixY = 0;
}
}
if (ab.pressed(A_BUTTON + DOWN_BUTTON)) {
isblackpixel();
PixY++;
ab.drawPixel(PixX, PixY, WHITE);
delay(200);
ab.display();
if (PixY >= 63) {
PixY = 63;
}
}
}
void isblackpixel() {
if (ab.getPixel(PixX, PixY) == BLACK) {
ab.drawPixel(PixX, PixY, WHITE);
}
}