Heliograde
Light Sensitive Sampling Process Microcontroller Software and Hardware Application (MSHA) Project.
Components and supplies
14
2x15 Pin Headers Socket 2.54mm Male & Female 4 Pair Connector
10
5 mm LED: Green
1
Ceramic Capacitor 1.2 nF
1
Ceramic Capacitor 10 nF
1
Photo resistor
1
Tactile Switch, Top Actuated
1
Male/Male Jumper Wires
1
USB-A to B Cable
1
Arduino UNO
10
Resistor 220 ohm
1
555 Timers
2
Resistor 100k ohm
1
9V battery (generic)
1
Through Hole Resistor, 680 ohm
Tools and machines
1
Soldering iron (generic)
1
Solder Wire, Lead Free
Project description
Code
Helliograde.ino
arduino
1int statesMaxLength = 600; 2 3class Timer555 4{ 5public: 6 int pin; 7 Timer555(int pin) 8 { 9 this->pin = pin; 10 } 11 int getCurrentState() 12 { 13 return digitalRead(this->pin); 14 } 15}; 16 17class LiteScopeBoard 18{ 19private: 20 unsigned long int millisPerHour = 3600000; 21 float T = 834.00; 22 float T_59 = this->T * 59.00 / 100.00; 23 float T_41 = this->T * 41.00 / 100.00; 24 float T_ratio = this->T_59 / this->T_41; 25 float float_stm = float(statesMaxLength); 26 float boardClock = 16000.00; 27 float clock_ratio = this->boardClock / this->float_stm; 28 float num_of_ones = 0.00; 29 float num_of_zeros = 0.00; 30 float one_cycle = 1.00; 31 int ledNum = 10; 32 int ledPins[10]; 33 int timerPin; 34 int switchModePin; 35 int getTimerPin(Timer555 t) 36 { 37 return t.pin; 38 } 39 40public: 41 unsigned long int counter = 0; 42 float cycles = 0.00; 43 int Helliogrades = 0; 44 LiteScopeBoard(Timer555 timer, int switchModePin, int l0, int l1, int l2, int l3, int l4, int l5, int l6, int l7, int l8, int l9) 45 { 46 this->timerPin = this->getTimerPin(timer); 47 this->switchModePin = switchModePin; 48 for (int i = 0; i < this->ledNum; i++) 49 { 50 switch (i) 51 { 52 case 0: 53 this->ledPins[i] = l0; 54 break; 55 case 1: 56 this->ledPins[i] = l1; 57 break; 58 case 2: 59 this->ledPins[i] = l2; 60 break; 61 case 3: 62 this->ledPins[i] = l3; 63 break; 64 case 4: 65 this->ledPins[i] = l4; 66 break; 67 case 5: 68 this->ledPins[i] = l5; 69 break; 70 case 6: 71 this->ledPins[i] = l6; 72 break; 73 case 7: 74 this->ledPins[i] = l7; 75 break; 76 case 8: 77 this->ledPins[i] = l8; 78 break; 79 case 9: 80 this->ledPins[i] = l9; 81 break; 82 } 83 } 84 } 85 void timerPinSetup() 86 { 87 pinMode(this->timerPin, INPUT); 88 } 89 void switchModePinSetup() 90 { 91 pinMode(this->switchModePin, INPUT); 92 } 93 void ledPinsSetup() 94 { 95 for (int i = 0; i < this->ledNum; i++) 96 { 97 pinMode(this->ledPins[i], OUTPUT); 98 } 99 } 100 void initialize() 101 { 102 delay(1000); 103 this->allLedsON(); 104 delay(1000); 105 this->allLedsOFF(); 106 if (Serial) 107 { 108 Serial.print("Timer Pin: "); 109 Serial.println(this->timerPin); 110 Serial.print("Switch Mode Pin: "); 111 Serial.println(this->switchModePin); 112 Serial.println(); 113 } 114 // sync / snap board to a timer's first and nearest ON state (logical 1) 115 while (digitalRead(this->timerPin) == 0) 116 { 117 ; 118 } 119 } 120 int getMode() 121 { 122 return digitalRead(this->switchModePin); 123 } 124 void count() 125 { 126 this->counter++; 127 } 128 void addCycles(Timer555 &t) 129 { 130 int state, del; 131 float cyclesRatio, runCycles; 132 for (int j = 0; j < 2; j++) 133 { 134 for (int i = 0; i < statesMaxLength; i++) 135 { 136 state = t.getCurrentState(); 137 switch (state) 138 { 139 case 0: 140 this->num_of_zeros++; 141 break; 142 case 1: 143 this->num_of_ones++; 144 break; 145 } 146 } 147 } 148 if (this->num_of_zeros != 0 && this->num_of_ones != 0) 149 { 150 cyclesRatio = float(this->num_of_ones) / float(this->num_of_zeros); 151 cyclesRatio /= this->T_ratio; 152 runCycles = this->one_cycle / cyclesRatio; 153 runCycles *= this->clock_ratio; 154 this->cycles += runCycles; 155 } 156 this->num_of_zeros = 0.00; 157 this->num_of_ones = 0.00; 158 del = int(this->T); 159 delayMicroseconds(del); 160 } 161 void ledON(int i) 162 { 163 digitalWrite(this->ledPins[i], HIGH); 164 } 165 void ledOFF(int i) 166 { 167 digitalWrite(this->ledPins[i], LOW); 168 } 169 void allLedsON() 170 { 171 for (int i = 0; i < this->ledNum; i++) 172 { 173 this->ledON(i); 174 } 175 } 176 void allLedsOFF() 177 { 178 for (int i = 0; i < this->ledNum; i++) 179 { 180 this->ledOFF(i); 181 } 182 } 183 void showStatus() 184 { 185 if (this->getMode() == 1) 186 { 187 if (Serial) 188 { 189 Serial.print("Board Loops counted: "); 190 Serial.print(this->counter); 191 Serial.println(); 192 Serial.print("Timer Cycles counted: "); 193 Serial.print(this->cycles); 194 Serial.println(); 195 Serial.println(); 196 } 197 } 198 } 199 void addHelliograde() 200 { 201 float float_hr; 202 int int_hr; 203 float_hr = this->cycles / float(this->millisPerHour); 204 int_hr = int(float_hr); 205 if (this->Helliogrades < int_hr) 206 { 207 if (int_hr >= 1 && int_hr <= 10) 208 { 209 this->Helliogrades++; 210 } 211 } 212 } 213 void showHelliogrades() 214 { 215 if (this->Helliogrades > 0) 216 { 217 for (int i = 0; i < this->Helliogrades; i++) 218 { 219 this->ledON(i); 220 } 221 } 222 } 223}; 224 225Timer555 timer(13); 226LiteScopeBoard board(timer, 12, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); 227 228void setup() 229{ 230 // ** THE FOLLOWING CODE WORKS PERFECT ON ARDUINO. ** 231 // ** SO, WE CAN INITIALIZE LOOP, AFTER SYNCING 232 // BOARD TO TIMER AT THE VERY FIRST TIMER'S 233 // ON STATE MOMENT 234 /*Serial.begin(9600); 235 pinMode(2, INPUT); 236 delay(1000); 237 while(digitalRead(2) == 0) { 238 ; 239 } 240 Serial.println("ok");*/ 241 Serial.begin(115200); 242 board.timerPinSetup(); 243 board.switchModePinSetup(); 244 board.ledPinsSetup(); 245 board.initialize(); 246} 247 248void loop() 249{ 250 board.count(); 251 board.addCycles(timer); 252 board.addHelliograde(); 253 board.showHelliogrades(); 254 board.showStatus(); 255} 256
Helliograde.ino
arduino
1int statesMaxLength = 600; 2 3class Timer555 4{ 5public: 6 int pin; 7 Timer555(int pin) 8 { 9 this->pin = pin; 10 } 11 int getCurrentState() 12 { 13 return digitalRead(this->pin); 14 } 15}; 16 17class LiteScopeBoard 18{ 19private: 20 unsigned long int millisPerHour = 3600000; 21 float T = 834.00; 22 float T_59 = this->T * 59.00 / 100.00; 23 float T_41 = this->T * 41.00 / 100.00; 24 float T_ratio = this->T_59 / this->T_41; 25 float float_stm = float(statesMaxLength); 26 float boardClock = 16000.00; 27 float clock_ratio = this->boardClock / this->float_stm; 28 float num_of_ones = 0.00; 29 float num_of_zeros = 0.00; 30 float one_cycle = 1.00; 31 int ledNum = 10; 32 int ledPins[10]; 33 int timerPin; 34 int switchModePin; 35 int getTimerPin(Timer555 t) 36 { 37 return t.pin; 38 } 39 40public: 41 unsigned long int counter = 0; 42 float cycles = 0.00; 43 int Helliogrades = 0; 44 LiteScopeBoard(Timer555 timer, int switchModePin, int l0, int l1, int l2, int l3, int l4, int l5, int l6, int l7, int l8, int l9) 45 { 46 this->timerPin = this->getTimerPin(timer); 47 this->switchModePin = switchModePin; 48 for (int i = 0; i < this->ledNum; i++) 49 { 50 switch (i) 51 { 52 case 0: 53 this->ledPins[i] = l0; 54 break; 55 case 1: 56 this->ledPins[i] = l1; 57 break; 58 case 2: 59 this->ledPins[i] = l2; 60 break; 61 case 3: 62 this->ledPins[i] = l3; 63 break; 64 case 4: 65 this->ledPins[i] = l4; 66 break; 67 case 5: 68 this->ledPins[i] = l5; 69 break; 70 case 6: 71 this->ledPins[i] = l6; 72 break; 73 case 7: 74 this->ledPins[i] = l7; 75 break; 76 case 8: 77 this->ledPins[i] = l8; 78 break; 79 case 9: 80 this->ledPins[i] = l9; 81 break; 82 } 83 } 84 } 85 void timerPinSetup() 86 { 87 pinMode(this->timerPin, INPUT); 88 } 89 void switchModePinSetup() 90 { 91 pinMode(this->switchModePin, INPUT); 92 } 93 void ledPinsSetup() 94 { 95 for (int i = 0; i < this->ledNum; i++) 96 { 97 pinMode(this->ledPins[i], OUTPUT); 98 } 99 } 100 void initialize() 101 { 102 delay(1000); 103 this->allLedsON(); 104 delay(1000); 105 this->allLedsOFF(); 106 if (Serial) 107 { 108 Serial.print("Timer Pin: "); 109 Serial.println(this->timerPin); 110 Serial.print("Switch Mode Pin: "); 111 Serial.println(this->switchModePin); 112 Serial.println(); 113 } 114 // sync / snap board to a timer's first and nearest ON state (logical 1) 115 while (digitalRead(this->timerPin) == 0) 116 { 117 ; 118 } 119 } 120 int getMode() 121 { 122 return digitalRead(this->switchModePin); 123 } 124 void count() 125 { 126 this->counter++; 127 } 128 void addCycles(Timer555 &t) 129 { 130 int state, del; 131 float cyclesRatio, runCycles; 132 for (int j = 0; j < 2; j++) 133 { 134 for (int i = 0; i < statesMaxLength; i++) 135 { 136 state = t.getCurrentState(); 137 switch (state) 138 { 139 case 0: 140 this->num_of_zeros++; 141 break; 142 case 1: 143 this->num_of_ones++; 144 break; 145 } 146 } 147 } 148 if (this->num_of_zeros != 0 && this->num_of_ones != 0) 149 { 150 cyclesRatio = float(this->num_of_ones) / float(this->num_of_zeros); 151 cyclesRatio /= this->T_ratio; 152 runCycles = this->one_cycle / cyclesRatio; 153 runCycles *= this->clock_ratio; 154 this->cycles += runCycles; 155 } 156 this->num_of_zeros = 0.00; 157 this->num_of_ones = 0.00; 158 del = int(this->T); 159 delayMicroseconds(del); 160 } 161 void ledON(int i) 162 { 163 digitalWrite(this->ledPins[i], HIGH); 164 } 165 void ledOFF(int i) 166 { 167 digitalWrite(this->ledPins[i], LOW); 168 } 169 void allLedsON() 170 { 171 for (int i = 0; i < this->ledNum; i++) 172 { 173 this->ledON(i); 174 } 175 } 176 void allLedsOFF() 177 { 178 for (int i = 0; i < this->ledNum; i++) 179 { 180 this->ledOFF(i); 181 } 182 } 183 void showStatus() 184 { 185 if (this->getMode() == 1) 186 { 187 if (Serial) 188 { 189 Serial.print("Board Loops counted: "); 190 Serial.print(this->counter); 191 Serial.println(); 192 Serial.print("Timer Cycles counted: "); 193 Serial.print(this->cycles); 194 Serial.println(); 195 Serial.println(); 196 } 197 } 198 } 199 void addHelliograde() 200 { 201 float float_hr; 202 int int_hr; 203 float_hr = this->cycles / float(this->millisPerHour); 204 int_hr = int(float_hr); 205 if (this->Helliogrades < int_hr) 206 { 207 if (int_hr >= 1 && int_hr <= 10) 208 { 209 this->Helliogrades++; 210 } 211 } 212 } 213 void showHelliogrades() 214 { 215 if (this->Helliogrades > 0) 216 { 217 for (int i = 0; i < this->Helliogrades; i++) 218 { 219 this->ledON(i); 220 } 221 } 222 } 223}; 224 225Timer555 timer(13); 226LiteScopeBoard board(timer, 12, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); 227 228void setup() 229{ 230 // ** THE FOLLOWING CODE WORKS PERFECT ON ARDUINO. ** 231 // ** SO, WE CAN INITIALIZE LOOP, AFTER SYNCING 232 // BOARD TO TIMER AT THE VERY FIRST TIMER'S 233 // ON STATE MOMENT 234 /*Serial.begin(9600); 235 pinMode(2, INPUT); 236 delay(1000); 237 while(digitalRead(2) == 0) { 238 ; 239 } 240 Serial.println("ok");*/ 241 Serial.begin(115200); 242 board.timerPinSetup(); 243 board.switchModePinSetup(); 244 board.ledPinsSetup(); 245 board.initialize(); 246} 247 248void loop() 249{ 250 board.count(); 251 board.addCycles(timer); 252 board.addHelliograde(); 253 board.showHelliogrades(); 254 board.showStatus(); 255} 256
Downloadable files
Helliograde Schematics
Helliograde Schematics

Helliograde Schematics
Helliograde Schematics

Helliograde PCB
Helliograde PCB

Documentation
Helliograde CAM
Helliograde CAM
Helliograde CAM
Helliograde CAM
Comments
Only logged in users can leave comments