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:
- 6:baece3338bfe
- Parent:
- 5:495d64d8934d
- Child:
- 7:2db895370298
- Child:
- 8:09efa61ef52c
diff -r 495d64d8934d -r baece3338bfe main.cpp
--- a/main.cpp Fri May 01 05:25:19 2015 +0000
+++ b/main.cpp Fri May 01 06:46:08 2015 +0000
@@ -2,6 +2,8 @@
#include "MRF24J40.h"
#include <string>
+#include <time.h>
+
#include "constants.h"
#include "shape_drawer.h"
@@ -84,7 +86,6 @@
int frame_id = 0;
char frame_buffer1[SLICES][WIDTH];
char frame_buffer2[SLICES][WIDTH];
-char work_buffer[SLICES][WIDTH];
int slice_i = 100;
BusOut blade(p15, p16, p17, p18, p19, p20, p21, p22);
@@ -147,8 +148,6 @@
/***************************************************************/
//code to adjust for offset blades and vertical alignment
-int displaces[HEIGHT];
-
void convert_array(){
if(frame_id == 0){
move_buffer(&frame_buffer2);
@@ -161,28 +160,36 @@
int display_mode = 0;
Ticker animate_ticker;
+
+int height(float d){
+ return 0;
+}
+
+float freq = 4;
+float freq_disp = 0.0;
+int wave_height(float d){
+ float h = 3.5*sin(2.0 * M_PI * (d + freq_disp) * freq) + 3.5;
+ return (int)rint(h);
+}
+
void animate(){
- for(int i = 0; i < SLICES; i++){
- for(int j = 0; j < WIDTH; j++){
- work_buffer[i][j] = 0x00;
- }
- }
-
if(display_mode == 1)
{
- static int disp = 0;
+ set_hfunc(&wave_height);
+
for(int i = 3; i < WIDTH; i++){
- draw_wavecircle(i, 4, disp);
+ draw_circle(i, 4);
}
- disp += 10;
- if(disp >= SLICES){
- disp = 0;
+ freq_disp += 0.1;
+ if(freq_disp >= 1.0){
+ freq_disp = 0.0;
}
}
else if(display_mode == 2)
{
+ set_hfunc(NULL);
draw_line(10, 10, 0, 10, -10, 0);
draw_line(10, -10, 0, -10, -10, 0);
draw_line(-10, -10, 0, -10, 10, 0);
@@ -201,11 +208,58 @@
}
else if(display_mode == 3)
{
+ int g = 4;
+ static bool init = false;
+ static int towers[4][4];
+
+ if(!init){
+ set_hfunc(NULL);
+ srand(time(NULL));
+
+ for(int i = 0; i < g; i++){
+ for(int j = 0; j < g; j++){
+ towers[i][j] = rand() % HEIGHT;
+ }
+ }
+ init = true;
+ }
+
+ int f = WIDTH / g;
+
+ for(int i = -g; i < g; i++){
+ for(int j = -g; j < g; j++){
+ int h = towers[i + g][j + g];
+
+ draw_line(i*f, j*f, 0, i*f, j*f + f, 0);
+ draw_line(i*f, j*f + f, 0, i*f + f, j*f + f, 0);
+ draw_line(i*f + f, j*f + f, 0, i*f + f, j*f, 0);
+ draw_line(i*f + f, j*f, 0, i*f, j*f, 0);
+
+ draw_line(i*f, j*f, 0, i*f, j*f, h);
+ draw_line(i*f + f, j*f, 0, i*f + f, j*f, h);
+ draw_line(i*f, j*f + f, 0, i*f, j*f + f, h);
+ draw_line(i*f + f, j*f + f, 0, i*f + f, j*f + f, h);
+
+ draw_line(i*f, j*f, h, i*f, j*f + f, h);
+ draw_line(i*f, j*f + f, h, i*f + f, j*f + f, h);
+ draw_line(i*f + f, j*f + f, h, i*f + f, j*f, h);
+ draw_line(i*f + f, j*f, h, i*f, j*f, h);
+ }
+ }
} else if(display_mode == 4){
- for(int i = -12; i < 13; i += 4){
+ freq = 1.5;
+ set_hfunc(&wave_height);
+
+
+ freq_disp += 0.05;
+ if(freq_disp >= 1.0){
+ freq_disp = 0.0;
+ }
+
+ for(int i = -12; i < 13; i += 1){
draw_line(i, 16, 0, i, -16, 0);
- draw_line(16, i, 0, -16, i, 0);
+ //draw_line(16, i, 0, -16, i, 0);
}
}
@@ -219,7 +273,7 @@
int main (void)
{
- display_mode = 1;
+ display_mode = 4;
InterruptIn hall_pin(p25);
hall_pin.fall(&rotate_sense);