Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:4b42ccb9df8d
- Parent:
- 1:4a50c0bbbf9d
- Child:
- 3:7e568908f1c4
--- a/main.cpp Thu Apr 30 21:42:29 2015 +0000
+++ b/main.cpp Fri May 01 01:16:51 2015 +0000
@@ -78,27 +78,75 @@
free(send_buf);
}
-char (*frame)[SLICES][WIDTH];
-char frame_buffer[2][SLICES][WIDTH];
+/*******************************************************************/
+// Display interrupt and drivers
+
+int frame_id = 0;
+char frame_buffer1[SLICES][WIDTH];
+char frame_buffer2[SLICES][WIDTH];
char work_buffer[SLICES][WIDTH];
-char hall_i = 0;
-int hall_t = 0;
-
-int rot_t_samples[5] = {0};
-char rot_i = 0;
-int rot_t = 100;
-
-void hall_int(){
- hall_i = 1;
-}
-
-int slice_i = 0;
+int slice_i = 100;
BusOut blade(p15, p16, p17, p18, p19, p20, p21, p22);
DigitalOut clk(p23);
DigitalOut disp(p24);
Ticker pixel_ticker;
+void push_pixels(){
+ for(int j = 8; j < WIDTH; j++){
+ if(frame_id == 0)
+ blade = frame_buffer1[slice_i][j];
+ else
+ blade = frame_buffer2[slice_i][j];
+
+ clk = 1;
+ clk = 0;
+ }
+
+ for(int j = 7; j >= 0; j--){
+ if(frame_id == 0)
+ blade = frame_buffer1[slice_i][j];
+ else
+ blade = frame_buffer2[slice_i][j];
+
+ clk = 1;
+ clk = 0;
+ }
+
+ disp = 1;
+ disp = 0;
+
+ slice_i = (slice_i + 1)%SLICES;
+}
+
+//Hall sensor interupt
+double rotate_time;
+double slice_time;
+
+Timer hall_timer;
+
+void rotate_sense(){
+ static bool firstTime = false;
+
+ if (firstTime){
+ hall_timer.reset();
+ hall_timer.start();
+ firstTime = false;
+ return;
+ }
+
+ rotate_time = hall_timer.read_us();
+ hall_timer.reset();
+ hall_timer.start();
+
+ slice_time = (double) rotate_time/SLICES;
+ slice_i = 0;
+ pixel_ticker.attach_us(&push_pixels, slice_time);
+}
+
+/***************************************************************/
+//code to adjust for offset blades and vertical alignment
+
int displaces[HEIGHT];
void init_displaces(){
@@ -116,58 +164,13 @@
}
}
-void push_pixels(){
- for(int j = 8; j < WIDTH; j++){
- blade = (*frame)[slice_i][j];
-
- clk = 1;
- clk = 0;
- }
-
- for(int j = 7; j >= 0; j--){
- blade = (*frame)[slice_i][j];
-
- clk = 1;
- clk = 0;
- }
-
- disp = 1;
- disp = 0;
-
- slice_i = (slice_i + 1)%SLICES;
-}
-
-//Hall sensor interupt
-bool firstTime;
-double rotate_time;
-double slice_time;
-
-Timer hall_timer;
-
-void rotate_sense(){
- if (firstTime){
- hall_timer.reset();
- hall_timer.start();
- firstTime = false;
- return;
- }
-
- rotate_time = hall_timer.read_us();
- hall_timer.reset();
- hall_timer.start();
-
- slice_time = (double) rotate_time/SLICES;
- slice_i = 0;
- pixel_ticker.attach_us(&push_pixels, slice_time);
-}
-
void convert_array(){
+ static bool initialized = false;
int array_i;
- if(frame == &frame_buffer[0])
- array_i = 1;
- else
- array_i = 0;
+ if(!initialized){
+ init_displaces();
+ }
for(int i = 0; i < SLICES; i++){
for(int j = 0; j < WIDTH; j++){
@@ -177,75 +180,173 @@
bit |= (work_buffer[(i + displaces[h]) % SLICES][j] & (0x01 << h));
}
- frame_buffer[array_i][i][j] = bit;
+ if(frame_id == 0)
+ frame_buffer2[i][j] = bit;
+ else
+ frame_buffer1[i][j] = bit;
}
}
- frame = &frame_buffer[array_i];
+ if(frame_id == 0)
+ frame_id = 1;
+ else
+ frame_id = 0;
+}
+
+int display_mode = 0;
+Ticker animate_ticker;
+void animate(){
+ static WaveCircle *wc1 = NULL;
+ static WaveCircle *wc2 = NULL;
+ static WaveCircle *wc3 = NULL;
+ static WaveCircle *wc4 = NULL;
+ static WaveCircle *wc5 = NULL;
+ static WaveCircle *wc6 = NULL;
+ static WaveCircle *wc7 = NULL;
+ static WaveCircle *wc8 = NULL;
+ static WaveCircle *wc9 = NULL;
+ static WaveCircle *wc10 = NULL;
+ static WaveCircle *wc11 = NULL;
+ static WaveCircle *wc12 = NULL;
+ static WaveCircle *wc13 = NULL;
+
+ for(int i = 0; i < SLICES; i++){
+ for(int j = 0; j < WIDTH; j++){
+ work_buffer[i][j] = 0x00;
+ }
+ }
+
+ if(display_mode == 1)
+ {
+ if(wc1 == NULL){
+ wc1 = new WaveCircle(3, 4, &work_buffer);
+ wc2 = new WaveCircle(4, 4, &work_buffer);
+ wc3 = new WaveCircle(5, 4, &work_buffer);
+ wc4 = new WaveCircle(6, 4, &work_buffer);
+ wc5 = new WaveCircle(7, 4, &work_buffer);
+ wc6 = new WaveCircle(8, 4, &work_buffer);
+ wc7 = new WaveCircle(9, 4, &work_buffer);
+ wc8 = new WaveCircle(10, 4, &work_buffer);
+ wc9 = new WaveCircle(11, 4, &work_buffer);
+ wc10 = new WaveCircle(12, 4, &work_buffer);
+ wc11 = new WaveCircle(13, 4, &work_buffer);
+ wc12 = new WaveCircle(14, 4, &work_buffer);
+ wc13 = new WaveCircle(15, 4, &work_buffer);
+ }
+
+ wc1->animate();
+ wc2->animate();
+ wc3->animate();
+ wc4->animate();
+ wc5->animate();
+ wc6->animate();
+ wc7->animate();
+ wc8->animate();
+ wc9->animate();
+ wc10->animate();
+ wc11->animate();
+ wc12->animate();
+ wc13->animate();
+
+ wc1->draw();
+ wc2->draw();
+ wc3->draw();
+ wc4->draw();
+ wc5->draw();
+ wc6->draw();
+ wc7->draw();
+ wc8->draw();
+ wc9->draw();
+ wc10->draw();
+ wc11->draw();
+ wc12->draw();
+ wc13->draw();
+ }
+ else if(display_mode == 2)
+ {
+ // Eight sided star
+ Line line1(15, 0, 0, 15, 90, 7, &work_buffer);
+ Line line2(15, 90, 7, 15, 180, 0, &work_buffer);
+ Line line3(15, 180, 0, 15, 270, 7, &work_buffer);
+ Line line4(15, 270, 7, 15, 0, 0, &work_buffer);
+ line1.draw();
+ line2.draw();
+ line3.draw();
+ line4.draw();
+
+ Line line5(15, 45, 0, 15, 135, 7, &work_buffer);
+ Line line6(15, 135, 7, 15, 225, 0, &work_buffer);
+ Line line7(15, 225, 0, 15, 315, 7, &work_buffer);
+ Line line8(15, 315, 7, 15, 45, 0, &work_buffer);
+ line5.draw();
+ line6.draw();
+ line7.draw();
+ line8.draw();
+ }
+ else if(display_mode == 3)
+ {
+ Line line1(1, 0, 0, 1, 0, 7, &work_buffer);
+ Line line2(9, 35, 0, 9, 35, 7, &work_buffer);
+ Line line3(9, 325, 0, 9, 325, 7, &work_buffer);
+ Line line4(13, 0, 0, 13, 0, 7, &work_buffer);
+
+ line1.draw();
+ line2.draw();
+ line3.draw();
+ line4.draw();
+
+ Line line5(M_PI * 320 / 180, 0.777030, 0, 0, 35, 0, &work_buffer);
+ Line line6(M_PI * 40 / 180, 0.777030, 0, 0, 325, 0, &work_buffer);
+ Line line7(M_PI * 320 / 180, 8.787681, 325, 0, 0, 0, &work_buffer);
+ Line line8(M_PI * 40 / 180, 8.787681, 35, 0, 0, 0, &work_buffer);
+
+ line5.draw();
+ line6.draw();
+ line7.draw();
+ line8.draw();
+
+ Line line9(M_PI * 320 / 180, 0.777030, 0, 7, 35, 7, &work_buffer);
+ Line line10(M_PI * 40 / 180, 0.777030, 0, 7, 325, 7, &work_buffer);
+ Line line11(M_PI * 320 / 180, 8.787681, 325, 7, 0, 7, &work_buffer);
+ Line line12(M_PI * 40 / 180, 8.787681, 35, 7, 0, 7, &work_buffer);
+
+ line9.draw();
+ line10.draw();
+ line11.draw();
+ line12.draw();
+ } else if(display_mode == 4){
+ CartLine line1(0, 16, 0, 0, -16, 0, &work_buffer);
+ CartLine line2(4, 16, 0, 4, -16, 0, &work_buffer);
+ CartLine line3(8, 16, 0, 8, -16, 0, &work_buffer);
+ CartLine line4(12, 16, 0, 12, -16, 0, &work_buffer);
+ CartLine line5(-4, 16, 0, -4, -16, 0, &work_buffer);
+ CartLine line6(-8, 16, 0, -8, -16, 0, &work_buffer);
+ CartLine line7(-12, 16, 0, -12, -16, 0, &work_buffer);
+
+ line1.draw();
+ line2.draw();
+ line3.draw();
+ line4.draw();
+ line5.draw();
+ line6.draw();
+ line7.draw();
+ }
+
+ convert_array();
+}
+
+bool animate_i = false;
+void animate_int(){
+ animate_i = true;
}
int main (void)
{
- firstTime = true;
- slice_i = 100;
- init_displaces();
-
- frame = &frame_buffer[0];
-
- /*
- Line line1(15, 0, 0, 15, 90, 7, &work_buffer);
- Line line2(15, 90, 7, 15, 180, 0, &work_buffer);
- Line line3(15, 180, 0, 15, 270, 7, &work_buffer);
- Line line4(15, 270, 7, 15, 0, 0, &work_buffer);
- line1.draw();
- line2.draw();
- line3.draw();
- line4.draw();
-
- Line line5(15, 45, 0, 15, 135, 7, &work_buffer);
- Line line6(15, 135, 7, 15, 225, 0, &work_buffer);
- Line line7(15, 225, 0, 15, 315, 7, &work_buffer);
- Line line8(15, 315, 7, 15, 45, 0, &work_buffer);
- line5.draw();
- line6.draw();
- line7.draw();
- line8.draw();
- */
-
- Line line1(1, 0, 0, 1, 0, 7, &work_buffer);
- Line line2(9, 35, 0, 9, 35, 7, &work_buffer);
- Line line3(9, 325, 0, 9, 325, 7, &work_buffer);
- Line line4(13, 0, 0, 13, 0, 7, &work_buffer);
-
- line1.draw();
- line2.draw();
- line3.draw();
- line4.draw();
-
- Line line5(M_PI * 320 / 180, 0.777030, 0, 0, 35, 0, &work_buffer);
- Line line6(M_PI * 40 / 180, 0.777030, 0, 0, 325, 0, &work_buffer);
- Line line7(M_PI * 320 / 180, 8.787681, 325, 0, 0, 0, &work_buffer);
- Line line8(M_PI * 40 / 180, 8.787681, 35, 0, 0, 0, &work_buffer);
-
- line5.draw();
- line6.draw();
- line7.draw();
- line8.draw();
-
- Line line9(M_PI * 320 / 180, 0.777030, 0, 7, 35, 7, &work_buffer);
- Line line10(M_PI * 40 / 180, 0.777030, 0, 7, 325, 7, &work_buffer);
- Line line11(M_PI * 320 / 180, 8.787681, 325, 7, 0, 7, &work_buffer);
- Line line12(M_PI * 40 / 180, 8.787681, 35, 7, 0, 7, &work_buffer);
-
- line9.draw();
- line10.draw();
- line11.draw();
- line12.draw();
-
- convert_array();
-
+ display_mode = 4;
+
InterruptIn hall_pin(p25);
hall_pin.fall(&rotate_sense);
+ animate_ticker.attach(&animate_int, 3.0);
uint8_t channel = 2;
@@ -253,6 +354,8 @@
mrf.SetChannel(channel);
while(true) {
-
+ if(animate_i){
+ animate();
+ }
}
}