A digital clock that can display a date and time using a Persistence of Vision Display

Dependencies:   NeoStrip mbed-rtos mbed

Committer:
nbharwani3
Date:
Wed May 04 18:02:02 2016 +0000
Revision:
1:551caed36fd6
Parent:
0:cf5f2628c1a0
Digital Persitence of Vision Clock for a final ECE 4180 project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nbharwani3 0:cf5f2628c1a0 1 #include "mbed.h"
nbharwani3 0:cf5f2628c1a0 2 #include "rtos.h"
nbharwani3 0:cf5f2628c1a0 3 #include "NeoStrip.h"
nbharwani3 0:cf5f2628c1a0 4
nbharwani3 0:cf5f2628c1a0 5 #define N 24
nbharwani3 0:cf5f2628c1a0 6 #define NUM_WIDTH 5
nbharwani3 0:cf5f2628c1a0 7 #define NUM_HEIGHT 7
nbharwani3 0:cf5f2628c1a0 8 #define CHARACTER_SIZE 7
nbharwani3 0:cf5f2628c1a0 9 #define WAIT_TIME 600
nbharwani3 0:cf5f2628c1a0 10
nbharwani3 0:cf5f2628c1a0 11 DigitalIn hall1(p15);
nbharwani3 0:cf5f2628c1a0 12 DigitalIn hall2(p16);
nbharwani3 0:cf5f2628c1a0 13
nbharwani3 0:cf5f2628c1a0 14 DigitalOut myled(LED1);
nbharwani3 0:cf5f2628c1a0 15 NeoStrip strip1(p11, N);
nbharwani3 0:cf5f2628c1a0 16 Serial usb(USBTX, USBRX);
nbharwani3 0:cf5f2628c1a0 17 //134125 = move backwards slowly
nbharwani3 0:cf5f2628c1a0 18 //135000 = move backwards slowly
nbharwani3 0:cf5f2628c1a0 19 //140000 = move forwards quickly
nbharwani3 0:cf5f2628c1a0 20 //136000 = move forward slowly
nbharwani3 0:cf5f2628c1a0 21 //135500 = move backwards slowly
nbharwani3 0:cf5f2628c1a0 22 //135750 = move backwards slowly
nbharwani3 0:cf5f2628c1a0 23 volatile int motor_speed_us = 135750;
nbharwani3 0:cf5f2628c1a0 24 volatile int one_degree_time = motor_speed_us/360;
nbharwani3 0:cf5f2628c1a0 25
nbharwani3 0:cf5f2628c1a0 26 volatile int startSeconds = 0;
nbharwani3 0:cf5f2628c1a0 27 volatile int startMinutes = 0;
nbharwani3 0:cf5f2628c1a0 28 volatile int startHours = 8;
nbharwani3 0:cf5f2628c1a0 29
nbharwani3 0:cf5f2628c1a0 30 time_t seconds;
nbharwani3 0:cf5f2628c1a0 31
nbharwani3 0:cf5f2628c1a0 32 int drawCharacter(char* character, int startNum_time, int startPos);
nbharwani3 0:cf5f2628c1a0 33
nbharwani3 0:cf5f2628c1a0 34 char zero [5] = {0b0000000, 0b0111110, 0b1000001, 0b1000001, 0b0111110};
nbharwani3 0:cf5f2628c1a0 35 char one [5] = {0b0000000, 0b0000000, 0b0100001, 0b1111111, 0b0000001};
nbharwani3 0:cf5f2628c1a0 36 char two [5] = {0b0000000, 0b0100011, 0b1000101, 0b1001001, 0b0110001};
nbharwani3 0:cf5f2628c1a0 37 char three [5] = {0b0000000, 0b1000001, 0b1001001, 0b1001001, 0b0110110};
nbharwani3 0:cf5f2628c1a0 38 char four [5] = {0b0000000, 0b1111000, 0b0001000, 0b0001000, 0b1111111};
nbharwani3 0:cf5f2628c1a0 39 char five [5] = {0b0000000, 0b1110010, 0b1001001, 0b1001001, 0b1000110};
nbharwani3 0:cf5f2628c1a0 40 char six [5] = {0b0000000, 0b0111110, 0b1001001, 0b1001001, 0b0100110};
nbharwani3 0:cf5f2628c1a0 41 char seven [5] = {0b0000000, 0b1000000, 0b1000111, 0b1011000, 0b1100000};
nbharwani3 0:cf5f2628c1a0 42 char eight [5] = {0b0000000, 0b0110110, 0b1001001, 0b1001001, 0b0110110};
nbharwani3 0:cf5f2628c1a0 43 char nine [5] = {0b0000000, 0b0110000, 0b1001001, 0b1001001, 0b0111110};
nbharwani3 0:cf5f2628c1a0 44 char colon [5] = {0b0000000, 0b0000000, 0b0110110, 0b0110110, 0b0000000};
nbharwani3 0:cf5f2628c1a0 45
nbharwani3 0:cf5f2628c1a0 46 char A [5] = {0b0111111, 0b1001000, 0b1001000, 0b1001000, 0b0111111};
nbharwani3 0:cf5f2628c1a0 47 char P [5] = {0b1111111, 0b1001000, 0b1001000, 0b1001000, 0b0110000};
nbharwani3 0:cf5f2628c1a0 48 char R [5] = {0b1111111, 0b1001000, 0b1001000, 0b1001100, 0b0110011};
nbharwani3 0:cf5f2628c1a0 49 char space [5] = {0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000};
nbharwani3 0:cf5f2628c1a0 50
nbharwani3 0:cf5f2628c1a0 51
nbharwani3 0:cf5f2628c1a0 52
nbharwani3 0:cf5f2628c1a0 53 Timer t;
nbharwani3 0:cf5f2628c1a0 54 Timer time_tracker;
nbharwani3 0:cf5f2628c1a0 55
nbharwani3 0:cf5f2628c1a0 56 //Will be issues of random orientation of the clock. Fix the issue with resynchronization using the magnet
nbharwani3 0:cf5f2628c1a0 57
nbharwani3 0:cf5f2628c1a0 58 void LEDstrip1_thread(void const *args)
nbharwani3 0:cf5f2628c1a0 59 {
nbharwani3 0:cf5f2628c1a0 60 t.start();
nbharwani3 0:cf5f2628c1a0 61 time_tracker.start();
nbharwani3 0:cf5f2628c1a0 62
nbharwani3 0:cf5f2628c1a0 63 int startNum_time = 50*one_degree_time - NUM_WIDTH/2;
nbharwani3 0:cf5f2628c1a0 64 int endNum_time = 50*one_degree_time + NUM_WIDTH/2;
nbharwani3 0:cf5f2628c1a0 65
nbharwani3 0:cf5f2628c1a0 66 bool wroteThisRotation = false;
nbharwani3 0:cf5f2628c1a0 67
nbharwani3 0:cf5f2628c1a0 68 strip1.setPixel(23, (uint8_t) 10,(uint8_t) 50,(uint8_t) 50);
nbharwani3 0:cf5f2628c1a0 69 strip1.setPixel(22, (uint8_t) 20,(uint8_t) 200,(uint8_t) 50);
nbharwani3 0:cf5f2628c1a0 70 strip1.setPixel(14,(uint8_t) 20,(uint8_t) 200,(uint8_t) 20);
nbharwani3 0:cf5f2628c1a0 71 strip1.setPixel(13,(uint8_t) 10,(uint8_t) 50,(uint8_t) 50);
nbharwani3 0:cf5f2628c1a0 72 strip1.setPixel(12,(uint8_t) 20,(uint8_t) 200,(uint8_t) 20);
nbharwani3 0:cf5f2628c1a0 73 strip1.setPixel(3, (uint8_t) 10,(uint8_t) 50,(uint8_t) 50);
nbharwani3 0:cf5f2628c1a0 74 strip1.setPixel(4, (uint8_t) 20,(uint8_t) 200,(uint8_t) 50);
nbharwani3 0:cf5f2628c1a0 75 while(1) {
nbharwani3 0:cf5f2628c1a0 76
nbharwani3 0:cf5f2628c1a0 77 int time = t.read_us();
nbharwani3 0:cf5f2628c1a0 78
nbharwani3 0:cf5f2628c1a0 79 if (time > startNum_time && !wroteThisRotation) {
nbharwani3 0:cf5f2628c1a0 80
nbharwani3 0:cf5f2628c1a0 81
nbharwani3 0:cf5f2628c1a0 82 int seconds = ((int)time_tracker.read() + startSeconds)%60;
nbharwani3 0:cf5f2628c1a0 83 int minutes = ((int)time_tracker.read()/60 + startMinutes)%60;
nbharwani3 0:cf5f2628c1a0 84 int hours = ((int)time_tracker.read()/3600 + startHours)%24;
nbharwani3 0:cf5f2628c1a0 85 bool AM = true;
nbharwani3 0:cf5f2628c1a0 86 if (hours >= 12) {
nbharwani3 0:cf5f2628c1a0 87 AM = false;
nbharwani3 0:cf5f2628c1a0 88 }
nbharwani3 0:cf5f2628c1a0 89 int printHours = hours % 12;
nbharwani3 0:cf5f2628c1a0 90 if (printHours == 0) {
nbharwani3 0:cf5f2628c1a0 91 printHours = 12;
nbharwani3 0:cf5f2628c1a0 92 }
nbharwani3 0:cf5f2628c1a0 93
nbharwani3 0:cf5f2628c1a0 94 char buf [10];
nbharwani3 0:cf5f2628c1a0 95 sprintf(buf, "%02i:%02i:%02i", hours, minutes, seconds);
nbharwani3 0:cf5f2628c1a0 96
nbharwani3 0:cf5f2628c1a0 97 for (int i = 8; i > 0; i--) {
nbharwani3 0:cf5f2628c1a0 98 if (buf[i] == '0') {
nbharwani3 0:cf5f2628c1a0 99 endNum_time = drawCharacter(zero, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 100 } else if (buf[i] == '1') {
nbharwani3 0:cf5f2628c1a0 101 endNum_time = drawCharacter(one, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 102 } else if (buf[i] == '2') {
nbharwani3 0:cf5f2628c1a0 103 endNum_time = drawCharacter(two, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 104 } else if (buf[i] == '3') {
nbharwani3 0:cf5f2628c1a0 105 endNum_time = drawCharacter(three, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 106 } else if (buf[i] == '4') {
nbharwani3 0:cf5f2628c1a0 107 endNum_time = drawCharacter(four, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 108 } else if (buf[i] == '5') {
nbharwani3 0:cf5f2628c1a0 109 endNum_time = drawCharacter(five, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 110 } else if (buf[i] == '6') {
nbharwani3 0:cf5f2628c1a0 111 endNum_time = drawCharacter(six, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 112 } else if (buf[i] == '7') {
nbharwani3 0:cf5f2628c1a0 113 endNum_time = drawCharacter(seven, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 114 } else if (buf[i] == '8') {
nbharwani3 0:cf5f2628c1a0 115 endNum_time = drawCharacter(eight, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 116 } else if (buf[i] == '9') {
nbharwani3 0:cf5f2628c1a0 117 endNum_time = drawCharacter(nine, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 118 } else if (buf[i] == ':') {
nbharwani3 0:cf5f2628c1a0 119 endNum_time = drawCharacter(colon, endNum_time,21);
nbharwani3 0:cf5f2628c1a0 120 }
nbharwani3 0:cf5f2628c1a0 121 }
nbharwani3 0:cf5f2628c1a0 122
nbharwani3 0:cf5f2628c1a0 123 char date[15];
nbharwani3 0:cf5f2628c1a0 124 sprintf(date,"APR 29 2016");
nbharwani3 0:cf5f2628c1a0 125
nbharwani3 0:cf5f2628c1a0 126 for (int i = 12; i >= 0; i--) {
nbharwani3 0:cf5f2628c1a0 127 if (date[i] == '0') {
nbharwani3 0:cf5f2628c1a0 128 endNum_time = drawCharacter(zero, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 129 } else if (date[i] == '1') {
nbharwani3 0:cf5f2628c1a0 130 endNum_time = drawCharacter(one, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 131 } else if (date[i] == '2') {
nbharwani3 0:cf5f2628c1a0 132 endNum_time = drawCharacter(two, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 133 } else if (date[i] == '3') {
nbharwani3 0:cf5f2628c1a0 134 endNum_time = drawCharacter(three, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 135 } else if (date[i] == '4') {
nbharwani3 0:cf5f2628c1a0 136 endNum_time = drawCharacter(four, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 137 } else if (date[i] == '5') {
nbharwani3 0:cf5f2628c1a0 138 endNum_time = drawCharacter(five, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 139 } else if (date[i] == '6') {
nbharwani3 0:cf5f2628c1a0 140 endNum_time = drawCharacter(six, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 141 } else if (date[i] == '7') {
nbharwani3 0:cf5f2628c1a0 142 endNum_time = drawCharacter(seven, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 143 } else if (date[i] == '8') {
nbharwani3 0:cf5f2628c1a0 144 endNum_time = drawCharacter(eight, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 145 } else if (date[i] == '9') {
nbharwani3 0:cf5f2628c1a0 146 endNum_time = drawCharacter(nine, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 147 } else if (date[i] == ':') {
nbharwani3 0:cf5f2628c1a0 148 endNum_time = drawCharacter(colon, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 149 } else if (date[i] == 'A') {
nbharwani3 0:cf5f2628c1a0 150 endNum_time = drawCharacter(A, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 151 } else if (date[i] == 'P') {
nbharwani3 0:cf5f2628c1a0 152 endNum_time = drawCharacter(P, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 153 } else if (date[i] == 'R') {
nbharwani3 0:cf5f2628c1a0 154 endNum_time = drawCharacter(R, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 155 } else if (date[i] == ' ') {
nbharwani3 0:cf5f2628c1a0 156 endNum_time = drawCharacter(space, endNum_time,11);
nbharwani3 0:cf5f2628c1a0 157 }
nbharwani3 0:cf5f2628c1a0 158 }
nbharwani3 0:cf5f2628c1a0 159 wroteThisRotation = true;
nbharwani3 0:cf5f2628c1a0 160 }
nbharwani3 0:cf5f2628c1a0 161 if (t.read_us() > motor_speed_us) {
nbharwani3 0:cf5f2628c1a0 162 t.reset();
nbharwani3 0:cf5f2628c1a0 163 //usb.printf("wroteThisRotation\n\r");
nbharwani3 0:cf5f2628c1a0 164 wroteThisRotation = false;
nbharwani3 0:cf5f2628c1a0 165 }
nbharwani3 0:cf5f2628c1a0 166 }
nbharwani3 0:cf5f2628c1a0 167 }
nbharwani3 0:cf5f2628c1a0 168 int drawCharacter(char* printable_number, int startNum_time, int startPos)
nbharwani3 0:cf5f2628c1a0 169 {
nbharwani3 0:cf5f2628c1a0 170
nbharwani3 0:cf5f2628c1a0 171 int time = t.read_us();
nbharwani3 0:cf5f2628c1a0 172
nbharwani3 0:cf5f2628c1a0 173 int number_column_repeats = CHARACTER_SIZE/NUM_WIDTH;
nbharwani3 0:cf5f2628c1a0 174 int count_num_trans = NUM_WIDTH - 1;
nbharwani3 0:cf5f2628c1a0 175
nbharwani3 0:cf5f2628c1a0 176 int transitionNum_time = startNum_time + number_column_repeats*one_degree_time;
nbharwani3 0:cf5f2628c1a0 177 int endNum_time = startNum_time + number_column_repeats*one_degree_time*NUM_WIDTH;
nbharwani3 0:cf5f2628c1a0 178
nbharwani3 0:cf5f2628c1a0 179
nbharwani3 0:cf5f2628c1a0 180 for (int i = 0; i < NUM_HEIGHT; i++) {
nbharwani3 0:cf5f2628c1a0 181 int litPixel = (printable_number[count_num_trans] & (1 << i))>>i;
nbharwani3 0:cf5f2628c1a0 182 strip1.setPixel(startPos-i, (uint8_t)0*litPixel,(uint8_t)0*litPixel,(uint8_t)100*litPixel);
nbharwani3 0:cf5f2628c1a0 183 //(uint8_t)0,(uint8_t)0,(uint8_t)40
nbharwani3 0:cf5f2628c1a0 184 //(uint8_t) 10*litPixel,(uint8_t) 50*litPixel,(uint8_t) 50*litPixel)
nbharwani3 0:cf5f2628c1a0 185 }
nbharwani3 0:cf5f2628c1a0 186
nbharwani3 0:cf5f2628c1a0 187
nbharwani3 0:cf5f2628c1a0 188 strip1.write();
nbharwani3 0:cf5f2628c1a0 189 //usb.printf("printable_number[%i] = %i", count_num_trans, printable_number[count_num_trans] );
nbharwani3 0:cf5f2628c1a0 190 count_num_trans = count_num_trans - 1;
nbharwani3 0:cf5f2628c1a0 191 wait_us(WAIT_TIME);
nbharwani3 0:cf5f2628c1a0 192 while (count_num_trans >= 0) {
nbharwani3 0:cf5f2628c1a0 193
nbharwani3 0:cf5f2628c1a0 194 //usb.printf("Attempting to print column %i bottom: %i\r\n", count_num_trans, printable_number[count_num_trans]);
nbharwani3 0:cf5f2628c1a0 195
nbharwani3 0:cf5f2628c1a0 196 for (int i = 0; i < NUM_HEIGHT; i++) {
nbharwani3 0:cf5f2628c1a0 197 int litPixel = (printable_number[count_num_trans] & (1 << i))>>i;
nbharwani3 0:cf5f2628c1a0 198 strip1.setPixel(startPos-i, (uint8_t)0*litPixel,(uint8_t)0*litPixel,(uint8_t)100*litPixel);
nbharwani3 0:cf5f2628c1a0 199 }
nbharwani3 0:cf5f2628c1a0 200
nbharwani3 0:cf5f2628c1a0 201
nbharwani3 0:cf5f2628c1a0 202
nbharwani3 0:cf5f2628c1a0 203 strip1.write();
nbharwani3 0:cf5f2628c1a0 204
nbharwani3 0:cf5f2628c1a0 205 count_num_trans = count_num_trans - 1;
nbharwani3 0:cf5f2628c1a0 206 transitionNum_time = (transitionNum_time + number_column_repeats*one_degree_time);
nbharwani3 0:cf5f2628c1a0 207 //wroteMiddle = true;
nbharwani3 0:cf5f2628c1a0 208 }
nbharwani3 0:cf5f2628c1a0 209 wait_us(WAIT_TIME);
nbharwani3 0:cf5f2628c1a0 210
nbharwani3 0:cf5f2628c1a0 211 //usb.printf("Number is finished printing\r\n");
nbharwani3 0:cf5f2628c1a0 212
nbharwani3 0:cf5f2628c1a0 213 for (int i = startPos; i > startPos-NUM_HEIGHT; i--) {
nbharwani3 0:cf5f2628c1a0 214
nbharwani3 0:cf5f2628c1a0 215 strip1.setPixel(i, 0,0,0);
nbharwani3 0:cf5f2628c1a0 216 }
nbharwani3 0:cf5f2628c1a0 217
nbharwani3 0:cf5f2628c1a0 218 // strip1.setPixel(22, 0,0,0);
nbharwani3 0:cf5f2628c1a0 219 // strip1.setPixel(21, 0,0,0);
nbharwani3 0:cf5f2628c1a0 220 // strip1.setPixel(20, 0,0,0);
nbharwani3 0:cf5f2628c1a0 221 // strip1.setPixel(19, 0,0,0);
nbharwani3 0:cf5f2628c1a0 222 // strip1.setPixel(18, 0,0,0);
nbharwani3 0:cf5f2628c1a0 223 //
nbharwani3 0:cf5f2628c1a0 224 strip1.write();
nbharwani3 0:cf5f2628c1a0 225 endNum_time = (endNum_time + one_degree_time) % motor_speed_us;
nbharwani3 0:cf5f2628c1a0 226 transitionNum_time = (startNum_time + one_degree_time*number_column_repeats) % motor_speed_us;
nbharwani3 0:cf5f2628c1a0 227 count_num_trans = NUM_WIDTH - 1;
nbharwani3 0:cf5f2628c1a0 228 wait_us(WAIT_TIME);
nbharwani3 0:cf5f2628c1a0 229
nbharwani3 0:cf5f2628c1a0 230 return endNum_time;
nbharwani3 0:cf5f2628c1a0 231 }
nbharwani3 0:cf5f2628c1a0 232
nbharwani3 0:cf5f2628c1a0 233
nbharwani3 0:cf5f2628c1a0 234 void HallEffect_thread(void const *args)
nbharwani3 0:cf5f2628c1a0 235 {
nbharwani3 0:cf5f2628c1a0 236 bool sensesMagnet = false;
nbharwani3 0:cf5f2628c1a0 237
nbharwani3 0:cf5f2628c1a0 238 hall1.mode(PullUp);
nbharwani3 0:cf5f2628c1a0 239 hall2.mode(PullUp);
nbharwani3 0:cf5f2628c1a0 240 Thread::wait(10);
nbharwani3 0:cf5f2628c1a0 241
nbharwani3 0:cf5f2628c1a0 242 while(1) {
nbharwani3 0:cf5f2628c1a0 243 if (!sensesMagnet && (hall1 == 0 || hall2 == 0)) {
nbharwani3 0:cf5f2628c1a0 244 sensesMagnet = true;
nbharwani3 0:cf5f2628c1a0 245 t.reset();
nbharwani3 0:cf5f2628c1a0 246 } else if (sensesMagnet && hall1 == 1 && hall2 == 1) {
nbharwani3 0:cf5f2628c1a0 247 sensesMagnet = false;
nbharwani3 0:cf5f2628c1a0 248 }
nbharwani3 0:cf5f2628c1a0 249 }
nbharwani3 0:cf5f2628c1a0 250 }
nbharwani3 0:cf5f2628c1a0 251
nbharwani3 0:cf5f2628c1a0 252
nbharwani3 0:cf5f2628c1a0 253
nbharwani3 0:cf5f2628c1a0 254
nbharwani3 0:cf5f2628c1a0 255 int main()
nbharwani3 0:cf5f2628c1a0 256 {
nbharwani3 0:cf5f2628c1a0 257
nbharwani3 0:cf5f2628c1a0 258 float brightness = 0.05f;
nbharwani3 0:cf5f2628c1a0 259 strip1.setBrightness(brightness);
nbharwani3 0:cf5f2628c1a0 260
nbharwani3 0:cf5f2628c1a0 261 for (int i = 0; i < N; i++) {
nbharwani3 0:cf5f2628c1a0 262 strip1.setPixel(i,0,0,0);
nbharwani3 0:cf5f2628c1a0 263 }
nbharwani3 0:cf5f2628c1a0 264
nbharwani3 0:cf5f2628c1a0 265 strip1.setPixel(1,0,(uint8_t)255,0);
nbharwani3 0:cf5f2628c1a0 266 strip1.write();
nbharwani3 0:cf5f2628c1a0 267
nbharwani3 0:cf5f2628c1a0 268 set_time(1461931200);
nbharwani3 0:cf5f2628c1a0 269 seconds = time(NULL); // get current time from mbed RTC
nbharwani3 0:cf5f2628c1a0 270
nbharwani3 0:cf5f2628c1a0 271 Thread thread2(LEDstrip1_thread);
nbharwani3 0:cf5f2628c1a0 272 Thread thread3(HallEffect_thread);
nbharwani3 0:cf5f2628c1a0 273
nbharwani3 0:cf5f2628c1a0 274 thread2.set_priority(osPriorityRealtime);
nbharwani3 0:cf5f2628c1a0 275 while(1) {
nbharwani3 0:cf5f2628c1a0 276 myled = 1;
nbharwani3 0:cf5f2628c1a0 277 wait(0.2);
nbharwani3 0:cf5f2628c1a0 278 myled = 0;
nbharwani3 0:cf5f2628c1a0 279 wait(0.2);
nbharwani3 0:cf5f2628c1a0 280 }
nbharwani3 0:cf5f2628c1a0 281
nbharwani3 0:cf5f2628c1a0 282 }
nbharwani3 0:cf5f2628c1a0 283
nbharwani3 0:cf5f2628c1a0 284
nbharwani3 0:cf5f2628c1a0 285
nbharwani3 0:cf5f2628c1a0 286
nbharwani3 0:cf5f2628c1a0 287
nbharwani3 0:cf5f2628c1a0 288
nbharwani3 0:cf5f2628c1a0 289
nbharwani3 0:cf5f2628c1a0 290
nbharwani3 0:cf5f2628c1a0 291
nbharwani3 0:cf5f2628c1a0 292
nbharwani3 0:cf5f2628c1a0 293
nbharwani3 0:cf5f2628c1a0 294
nbharwani3 0:cf5f2628c1a0 295
nbharwani3 0:cf5f2628c1a0 296
nbharwani3 0:cf5f2628c1a0 297
nbharwani3 0:cf5f2628c1a0 298 // if (time < transitionNum_time && time > endNum_time) {
nbharwani3 0:cf5f2628c1a0 299 //
nbharwani3 0:cf5f2628c1a0 300 //
nbharwani3 0:cf5f2628c1a0 301 // usb.printf("Attempting to print column %i top: %i\r\n", count_num_trans, printable_number[count_num_trans]);
nbharwani3 0:cf5f2628c1a0 302 //
nbharwani3 0:cf5f2628c1a0 303 // int led22 = printable_number [count_num_trans] & 0x01;
nbharwani3 0:cf5f2628c1a0 304 // int led21 = (printable_number [count_num_trans] & 0x02)>>1;
nbharwani3 0:cf5f2628c1a0 305 // int led20 = (printable_number [count_num_trans] & 0x04)>>2;
nbharwani3 0:cf5f2628c1a0 306 // int led19 = (printable_number [count_num_trans] & 0x08)>>3;
nbharwani3 0:cf5f2628c1a0 307 // int led18 = (printable_number [count_num_trans] & 0x10)>>4;
nbharwani3 0:cf5f2628c1a0 308 //
nbharwani3 0:cf5f2628c1a0 309 // strip1.setPixel(22, (uint8_t)(led22*255),0,0);
nbharwani3 0:cf5f2628c1a0 310 // strip1.setPixel(21, (uint8_t)(led21*255),0,0);
nbharwani3 0:cf5f2628c1a0 311 // strip1.setPixel(20, (uint8_t)(led20*255),0,0);
nbharwani3 0:cf5f2628c1a0 312 // strip1.setPixel(19, (uint8_t)(led19*255),0,0);
nbharwani3 0:cf5f2628c1a0 313 // strip1.setPixel(18, (uint8_t)(led18*255),0,0);
nbharwani3 0:cf5f2628c1a0 314 //
nbharwani3 0:cf5f2628c1a0 315 // strip1.write();
nbharwani3 0:cf5f2628c1a0 316 //
nbharwani3 0:cf5f2628c1a0 317 // count_num_trans = (count_num_trans + 1)%NUM_WIDTH;
nbharwani3 0:cf5f2628c1a0 318 // transitionNum_time = (transitionNum_time + number_column_repeats*one_degree_time);
nbharwani3 0:cf5f2628c1a0 319 // wroteMiddle = true;
nbharwani3 0:cf5f2628c1a0 320 // }
nbharwani3 0:cf5f2628c1a0 321 // } else {
nbharwani3 0:cf5f2628c1a0 322
nbharwani3 0:cf5f2628c1a0 323
nbharwani3 0:cf5f2628c1a0 324
nbharwani3 0:cf5f2628c1a0 325
nbharwani3 0:cf5f2628c1a0 326
nbharwani3 0:cf5f2628c1a0 327
nbharwani3 0:cf5f2628c1a0 328
nbharwani3 0:cf5f2628c1a0 329
nbharwani3 0:cf5f2628c1a0 330
nbharwani3 0:cf5f2628c1a0 331
nbharwani3 0:cf5f2628c1a0 332 //
nbharwani3 0:cf5f2628c1a0 333 //
nbharwani3 0:cf5f2628c1a0 334 //
nbharwani3 0:cf5f2628c1a0 335 //
nbharwani3 0:cf5f2628c1a0 336 //
nbharwani3 0:cf5f2628c1a0 337 // int time = t.read_us();
nbharwani3 0:cf5f2628c1a0 338 //
nbharwani3 0:cf5f2628c1a0 339 // int number_column_repeats = CHARACTER_SIZE/NUM_WIDTH;
nbharwani3 0:cf5f2628c1a0 340 // int count_num_trans = 0;
nbharwani3 0:cf5f2628c1a0 341 //
nbharwani3 0:cf5f2628c1a0 342 // int transitionNum_time = startNum_time + number_column_repeats*one_degree_time;
nbharwani3 0:cf5f2628c1a0 343 // int endNum_time = startNum_time + number_column_repeats*one_degree_time*NUM_WIDTH;
nbharwani3 0:cf5f2628c1a0 344 //
nbharwani3 0:cf5f2628c1a0 345 // usb.printf("startNum_time: %i\r\n", startNum_time);
nbharwani3 0:cf5f2628c1a0 346 // usb.printf("transitionNum_time: %i\r\n", transitionNum_time);
nbharwani3 0:cf5f2628c1a0 347 // usb.printf("endNum_time: %i\r\n", endNum_time);
nbharwani3 0:cf5f2628c1a0 348 //
nbharwani3 0:cf5f2628c1a0 349 // int led22 = printable_number [count_num_trans] & 0x01;
nbharwani3 0:cf5f2628c1a0 350 // int led21 = (printable_number [count_num_trans] & 0x02)>>1;
nbharwani3 0:cf5f2628c1a0 351 // int led20 = (printable_number [count_num_trans] & 0x04)>>2;
nbharwani3 0:cf5f2628c1a0 352 // int led19 = (printable_number [count_num_trans] & 0x08)>>3;
nbharwani3 0:cf5f2628c1a0 353 // int led18 = (printable_number [count_num_trans] & 0x10)>>4;
nbharwani3 0:cf5f2628c1a0 354 //
nbharwani3 0:cf5f2628c1a0 355 // strip1.setPixel(22, (uint8_t)(led22*255),0,0);
nbharwani3 0:cf5f2628c1a0 356 // strip1.setPixel(21, (uint8_t)(led21*255),0,0);
nbharwani3 0:cf5f2628c1a0 357 // strip1.setPixel(20, (uint8_t)(led20*255),0,0);
nbharwani3 0:cf5f2628c1a0 358 // strip1.setPixel(19, (uint8_t)(led19*255),0,0);
nbharwani3 0:cf5f2628c1a0 359 // strip1.setPixel(18, (uint8_t)(led18*255),0,0);
nbharwani3 0:cf5f2628c1a0 360 //
nbharwani3 0:cf5f2628c1a0 361 // strip1.write();
nbharwani3 0:cf5f2628c1a0 362 // usb.printf("printable_number[%i] = %i", count_num_trans, printable_number[count_num_trans] );
nbharwani3 0:cf5f2628c1a0 363 // count_num_trans = count_num_trans + 1;
nbharwani3 0:cf5f2628c1a0 364 //
nbharwani3 0:cf5f2628c1a0 365 // while (count_num_trans < NUM_WIDTH) {
nbharwani3 0:cf5f2628c1a0 366 // int time = t.read_us();
nbharwani3 0:cf5f2628c1a0 367 // if (time > transitionNum_time) {
nbharwani3 0:cf5f2628c1a0 368 //
nbharwani3 0:cf5f2628c1a0 369 //
nbharwani3 0:cf5f2628c1a0 370 // usb.printf("Attempting to print column %i bottom: %i\r\n", count_num_trans, printable_number[count_num_trans]);
nbharwani3 0:cf5f2628c1a0 371 //
nbharwani3 0:cf5f2628c1a0 372 // int led22 = printable_number [count_num_trans] & 0x01;
nbharwani3 0:cf5f2628c1a0 373 // int led21 = (printable_number [count_num_trans] & 0x02)>>1;
nbharwani3 0:cf5f2628c1a0 374 // int led20 = (printable_number [count_num_trans] & 0x04)>>2;
nbharwani3 0:cf5f2628c1a0 375 // int led19 = (printable_number [count_num_trans] & 0x08)>>3;
nbharwani3 0:cf5f2628c1a0 376 // int led18 = (printable_number [count_num_trans] & 0x10)>>4;
nbharwani3 0:cf5f2628c1a0 377 //
nbharwani3 0:cf5f2628c1a0 378 // strip1.setPixel(22, (uint8_t)(led22*255),0,0);
nbharwani3 0:cf5f2628c1a0 379 // strip1.setPixel(21, (uint8_t)(led21*255),0,0);
nbharwani3 0:cf5f2628c1a0 380 // strip1.setPixel(20, (uint8_t)(led20*255),0,0);
nbharwani3 0:cf5f2628c1a0 381 // strip1.setPixel(19, (uint8_t)(led19*255),0,0);
nbharwani3 0:cf5f2628c1a0 382 // strip1.setPixel(18, (uint8_t)(led18*255),0,0);
nbharwani3 0:cf5f2628c1a0 383 //
nbharwani3 0:cf5f2628c1a0 384 // strip1.write();
nbharwani3 0:cf5f2628c1a0 385 //
nbharwani3 0:cf5f2628c1a0 386 // count_num_trans = count_num_trans + 1;
nbharwani3 0:cf5f2628c1a0 387 // transitionNum_time = (transitionNum_time + number_column_repeats*one_degree_time);
nbharwani3 0:cf5f2628c1a0 388 // //wroteMiddle = true;
nbharwani3 0:cf5f2628c1a0 389 // }
nbharwani3 0:cf5f2628c1a0 390 // }
nbharwani3 0:cf5f2628c1a0 391 // bool wroteEnd = false;
nbharwani3 0:cf5f2628c1a0 392 //
nbharwani3 0:cf5f2628c1a0 393 // while (!wroteEnd){
nbharwani3 0:cf5f2628c1a0 394 // // usb.printf("end time %i, current time: %i \r\n", endNum_time, time);
nbharwani3 0:cf5f2628c1a0 395 // int time = t.read_us();
nbharwani3 0:cf5f2628c1a0 396 //
nbharwani3 0:cf5f2628c1a0 397 // if ( time > endNum_time) {
nbharwani3 0:cf5f2628c1a0 398 // usb.printf("Number is finished printing\r\n");
nbharwani3 0:cf5f2628c1a0 399 //
nbharwani3 0:cf5f2628c1a0 400 // strip1.setPixel(22, 0,0,0);
nbharwani3 0:cf5f2628c1a0 401 // strip1.setPixel(21, 0,0,0);
nbharwani3 0:cf5f2628c1a0 402 // strip1.setPixel(20, 0,0,0);
nbharwani3 0:cf5f2628c1a0 403 // strip1.setPixel(19, 0,0,0);
nbharwani3 0:cf5f2628c1a0 404 // strip1.setPixel(18, 0,0,0);
nbharwani3 0:cf5f2628c1a0 405 //
nbharwani3 0:cf5f2628c1a0 406 // strip1.write();
nbharwani3 0:cf5f2628c1a0 407 // endNum_time = (endNum_time + one_degree_time) % motor_speed_us;
nbharwani3 0:cf5f2628c1a0 408 // transitionNum_time = (startNum_time + one_degree_time*number_column_repeats) % motor_speed_us;
nbharwani3 0:cf5f2628c1a0 409 // count_num_trans = 0;
nbharwani3 0:cf5f2628c1a0 410 // return endNum_time;
nbharwani3 0:cf5f2628c1a0 411 //
nbharwani3 0:cf5f2628c1a0 412 // }
nbharwani3 0:cf5f2628c1a0 413 // }
nbharwani3 0:cf5f2628c1a0 414 // return endNum_time;
nbharwani3 0:cf5f2628c1a0 415 //}