Components and supplies
2N7000 MOSFET TO92
9Volts wall power supply
Breadboard power supply module
3Volts 5mW Laser Head
5Volts 3000 rpm DC motor
DS3231 RTC Module
1N4148 diode
Breadboard (generic)
Arduino Mega 2560
Pass through groove IR sensor
1\\4 Watt resistors
Jumper wires
Tools and machines
Solder wire
Soldering iron (generic)
Project description
Code
Program For Uploading Time On The RTC
c_cpp
1//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2//Sketch for uploading time on the RTC chip (adjust this sketch with 5 minutes more -> burn it -> disconnect the Arduino power 3//-> stick battery on the module -> connect the RTC to the board -> plug the USB at the exact time and open serial monitor)(don't connect it again) 4 5#include <Wire.h> 6 7void setup() { 8 Serial.begin(9600); 9 Wire.begin(); 10 11 Wire.beginTransmission(0x68); // address of the RTC (do not modify) 12 Wire.write(byte(0x00)); // address of the first data byte (seconds) (do not modify) 13 14 Wire.write(byte(0x00)); // seconds (from 0x00 to 0x59) 15 Wire.write(byte(0x30)); // minutes (from 0x00 to 0x59) 16 Wire.write(byte(0x10)); // hours (from 0x00 to 0x23) 17 Wire.write(byte(0x04)); // day of the week (from 0x01 to 0x07)(this is arbitrary) 18 Wire.write(byte(0x26)); // day of the month (from 0x01 to 0x31)(this is NOT arbitrary) 19 Wire.write(byte(0x05)); // month (from 0x01 to 0x12) 20 Wire.write(byte(0x16)); // year (from 0x00 to 0x99) 21 22 Wire.endTransmission(); 23} 24 25void loop() { 26 delay(1000); 27 28 Wire.beginTransmission(0x68); 29 Wire.write(byte(0x00)); 30 Wire.endTransmission(); 31 32 Wire.requestFrom(0x68, 7); 33 byte seconds = Wire.read(); 34 byte minutes = Wire.read(); 35 byte hours = Wire.read(); 36 byte dayWeek = Wire.read(); 37 byte dayMonth = Wire.read(); 38 byte month = Wire.read(); 39 byte year = Wire.read(); 40 41 Serial.print("Right now it's: "); 42 Serial.print(hours, HEX); 43 Serial.print(":"); 44 Serial.print(minutes, HEX); 45 Serial.print(":"); 46 Serial.println(seconds, HEX); 47 48 Serial.print("Today is day "); 49 Serial.print(dayWeek); 50 Serial.println(" of the week"); 51 52 Serial.print("Current date is: "); 53 Serial.print(dayMonth, HEX); 54 Serial.print("/"); 55 Serial.print(month, HEX); 56 Serial.print("/20"); 57 Serial.println(year, HEX); 58 Serial.println(); 59} 60
Arduino I2C Master Library
It's an alternative to the Wire library that doesn't rely on interrupts (useful to use inside an ISR, the Wire library CANNOT run inside an ISR), GIthub has the initial release, consider taking the latter from their website.
Main Program
c_cpp
1/* 2Arduino program for the Laser Projector Wall Clock 3 4Copyright (C) 2016 Genny A. Carogna 5 6This program is free software: you can redistribute it and/or modify 7it under the terms of the GNU General Public License as published by 8the Free Software Foundation, either version 3 of the License, or 9(at your option) any later version. 10 11This program is distributed in the hope that it will be useful, 12but WITHOUT ANY WARRANTY; without even the implied warranty of 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14GNU General Public License for more details. 15 16You should have received a copy of the GNU General Public License 17along with this program. If not, see <http://www.gnu.org/licenses/>. 18*/ 19 20 21#include <I2C.h> // you must install the "Arduino I2C Master Library" before 22 23#define dOn PORTE=B00100000; // PE5 pin3 // dim tracts signal (clock face) 24#define dOff PORTE=0; 25 26#define mOn PORTG=B00100000; // PG5 pin4 // medium intensity tract signal (hours) 27#define mOff PORTG=0; 28 29#define bOn PORTH=B00001000; // PH3 pin6 // full power (yeah!!) tracts signal (minutes and seconds) 30#define bOff PORTH=0; 31 32#define dimPin 3 33#define mediumPin 4 34#define brightPin 6 35#define tachoPin 18 36 37#define qTractStart 0.1 // 1/12 turn "percentage" // quadrant 38#define qTractEnd 0.9 39#define hTractStart 0.3 // 1/12 turn "percentage" // hour arm 40#define hTractEnd 0.7 41 42#define loopPeriod 150 // milliseconds 43 44volatile unsigned int TurnPeriod = 65000; // this stores the time necessary for an actual turn (in "16MHz /8" units) 45volatile bool reverse; // this goes "1" during 11:XX and 00:XX 46 47volatile unsigned int ocr1a = 32000; 48//volatile unsigned int ocr3a = 32000; 49volatile unsigned int ocr4a = 32000; 50//volatile unsigned int ocr5a = 32000; 51volatile unsigned int ocr1b = 32000; 52volatile unsigned int ocr3b = 32000; 53volatile unsigned int ocr4b = 32000; 54volatile unsigned int ocr5b = 32000; 55volatile unsigned int ocr1c = 32000; 56volatile unsigned int ocr3c = 32000; 57volatile unsigned int ocr4c = 32000; 58volatile unsigned int ocr5c = 32000; 59 60void setup(){ 61 pinMode(dimPin, OUTPUT); 62 pinMode(mediumPin, OUTPUT); 63 pinMode(brightPin, OUTPUT); 64 65 attachInterrupt(digitalPinToInterrupt(tachoPin), tacho, FALLING); 66 67 I2c.begin(); 68 69 cli(); 70 TCCR0A = 0; // disabling disturbing (maybe) stuff, this disables millis(), micros() and delay() 71 TCCR0B = 0; // 72 TIMSK0 = 0; // 73 74 //no prescaler for timer 1 75 TCCR1A = 0; 76 TCCR1B = 0; 77 TCCR1C = 0; 78 TIMSK1 = 0; 79 TCNT1 = 0; 80 OCR1A = 65000; 81 OCR1B = 30000; 82 OCR1C = 20000; 83 TCCR1B |= (1 << WGM12); // CTC enabled only for timer1 84 TCCR1B |= (1 << CS10); 85 //TIMSK1 |= (1 << OCIE1A); // we actually don't need an interrupt on "1A" 86 TIMSK1 |= (1 << OCIE1B); 87 TIMSK1 |= (1 << OCIE1C); 88 89 // /8 prescaler for others 90 TCCR3A = 0; 91 TCCR3B = 0; 92 TCCR3C = 0; 93 TIMSK3 = 0; 94 TCNT3 = 0; 95 OCR3A = 65000; 96 OCR3B = 64000; 97 OCR3C = 63000; 98 TCCR3B |= (1 << CS31); 99 //TIMSK3 |= (1 << OCIE3A); 100 TIMSK3 |= (1 << OCIE3B); 101 TIMSK3 |= (1 << OCIE3C); 102 103 TCCR4A = 0; 104 TCCR4B = 0; 105 TCCR4C = 0; 106 TIMSK4 = 0; 107 TCNT4 = 0; 108 OCR4A = 65000; 109 OCR4B = 64000; 110 OCR4C = 63000; 111 TCCR4B |= (1 << CS41); 112 TIMSK4 |= (1 << OCIE4A); 113 TIMSK4 |= (1 << OCIE4B); 114 TIMSK4 |= (1 << OCIE4C); 115 116 TCCR5A = 0; 117 TCCR5B = 0; 118 TCCR5C = 0; 119 TIMSK5 = 0; 120 TCNT5 = 0; 121 OCR5A = 65000; 122 OCR5B = 64000; 123 OCR5C = 63000; 124 TCCR5B |= (1 << CS51); 125 //TIMSK5 |= (1 << OCIE5A); 126 TIMSK5 |= (1 << OCIE5B); 127 TIMSK5 |= (1 << OCIE5C); 128 129 sei(); 130} 131 132void loop(){ 133 // you can add stuff in loop(), like a way to set the time with buttons 134 135 for (byte i = 0; i < 100; i ++) { 136 delayMicroseconds(loopPeriod * 10); 137 } // only delayMicroseconds() works with timer0 disabled 138 139 I2c.read(0x68, 0x00, 3); 140 byte temp0 = I2c.receive(); 141 byte temp1 = temp0 >> 4; // with Dallas RTCs time is stored as BCD (Binary Coded Decimal) 142 unsigned int seconds = (temp1 * 10) + (temp0 & B00001111); // with Dallas RTCs time is stored as BCD (Binary Coded Decimal) 143 144 temp0 = I2c.receive(); 145 temp1 = temp0 >> 4; 146 unsigned int minutes = (temp1 * 10) + (temp0 & B00001111); 147 148 temp0 = I2c.receive(); 149 temp1 = temp0 >> 4; 150 unsigned int hours = (temp1 * 10) + (temp0 & B00001111); 151 if (hours >= 12) hours -= 12; // lets keep it in 12 hours format 152 153 if(hours == 0 || hours == 11) { 154 reverse = 1; // for having a contiguous track for the hours arm we reset timer3 at 6:00 position during 11:XX and 00:XX 155 } 156 else reverse = 0; 157 158 cli(); 159 unsigned int turnPeriod = TurnPeriod; 160 sei(); 161 162 //A,B e C happen in reverse order (CBA) 163 ocr1a = (turnPeriod / 3) * 2; // dim, end of the hour (turnPeriod / 12) * 8 164 165 //ocr3a = 166 167 ocr4a = turnPeriod / 2; // six o'clock (used for the "reverse" case) 168 169 //ocr5a = 170 171 ocr1b = ocr1a * qTractEnd; // dim, end of the drawn quadrant hour tract 172 173 ocr3b = (((turnPeriod / 12) * hTractEnd) + ((turnPeriod / 720) * minutes)) - (turnPeriod / 24); // hours, end of the drawn tract 174 if (hours == 0) ocr3b += turnPeriod / 2; // ((turnPeriod / 12) * 6) 175 else if (hours == 11) ocr3b += (turnPeriod / 12) * 5; 176 else ocr3b += (turnPeriod / 12) * hours; 177 178 float mRatioEnd = float(minutes + 1) / 60; 179 ocr4b = (turnPeriod * mRatioEnd); // minutes, end of the drawn tract 180 181 float sRatio = float(seconds) / 60; 182 ocr5b = (turnPeriod * sRatio) + (turnPeriod / 80); // seconds, end of the drawn tract // (turnPeriod / (60 * 4)) * 3 183 184 ocr1c = ocr1a * qTractStart; // dim, start of the drawn quadrant hour tract 185 186 ocr3c = (((turnPeriod / 12) * hTractStart) + ((turnPeriod / 720) * minutes)) - (turnPeriod / 24); // hours, start of the drawn tract 187 if (hours == 0) ocr3c += turnPeriod / 2; // ((turnPeriod / 12) * 6) 188 else if (hours == 11) ocr3c += (turnPeriod / 12) * 5; 189 else ocr3c += (turnPeriod / 12) * hours; 190 191 float mRatioStart = float(minutes) / 60; 192 ocr4c = turnPeriod * mRatioStart; // minutes, start of the drawn tract 193 if (ocr4c < 100) ocr4c = 100; // lets try to NOT trigger a compare exactly when a timer resets and lets the "tacho" do it's job 194 195 ocr5c = (turnPeriod * sRatio) + (turnPeriod / 240); // seconds, start of the drawn tract // turnPeriod / (60 * 4) 196} 197 198void tacho() { 199 dOff 200 bOff 201 202 OCR1A = ocr1a; // refresh trigger points on various timers 203 //OCR3A = ocr3a; // 204 OCR4A = ocr4a; // 205 //OCR5A = ocr5a; // 206 OCR1B = ocr1b; // 207 OCR3B = ocr3b; // 208 OCR4B = ocr4b; // 209 OCR5B = ocr5b; // 210 OCR1C = ocr1c; // 211 OCR3C = ocr3c; // 212 OCR4C = ocr4c; // 213 OCR5C = ocr5c; // 214 215 TurnPeriod = TCNT4; // read motor speed for calculations 216 217 TCNT1 = 0; // restart timers 218 TCNT4 = 0; // 219 TCNT5 = 0; // 220 if (!reverse) { 221 TCNT3 = 0; // this in case we are NOT at 11:XX or 00:XX 222 mOff 223 } 224} 225 226 227 228/* 229ISR(TIMER1_COMPA_vect){ 230 231} 232*/ 233ISR(TIMER1_COMPB_vect){ 234 dOff // comment this for reversed quadrant picture (small tracts at "o'clocks" VS. big tracts into the hour span (default)) 235 //dOn // uncomment this for reversed quadrant picture 236} 237 238ISR(TIMER1_COMPC_vect){ 239 dOn // comment this for reversed quadrant picture 240 //dOff // uncomment this for reversed quadrant picture 241} 242 243 244/* 245ISR(TIMER3_COMPA_vect){ 246 247} 248*/ 249ISR(TIMER3_COMPB_vect){ 250 mOff // hour, end of the tract 251} 252 253ISR(TIMER3_COMPC_vect){ 254 mOn // hour, start of the tract 255} 256 257 258 259 260ISR(TIMER4_COMPA_vect){ 261 if (reverse) { // this in case we ARE at 11:XX or 00:XX 262 TCNT3 = 0; 263 mOff 264 } 265} 266 267ISR(TIMER4_COMPB_vect){ 268 bOff // minutes, end of the tract 269} 270 271ISR(TIMER4_COMPC_vect){ 272 bOn // minutes, start of the tract 273} 274 275 276 277/* 278ISR(TIMER5_COMPA_vect){ 279 280} 281*/ 282ISR(TIMER5_COMPB_vect){ 283 bOff // seconds, end of the tract 284} 285 286ISR(TIMER5_COMPC_vect){ 287 bOn // seconds, start of the tract 288} 289
Arduino I2C Master Library
It's an alternative to the Wire library that doesn't rely on interrupts (useful to use inside an ISR, the Wire library CANNOT run inside an ISR), GIthub has the initial release, consider taking the latter from their website.
Program For Reading Motor Speed (can be usefull)
c_cpp
1///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2//Sketch for reading motor speed, pin18 is intended for the Arduino Mega, value displayed on serial monitor is microseconds period 3//for one turn so if it's 19500 it means 0.0195 seconds and it means (1/X) ~50Hz and it means (X * 60) 3000 rpm (revolutions per minute) 4 5#define interruptPin 18 // intended for the Mega 6 7volatile unsigned long j = 0; 8 9void setup() { 10 Serial.begin(9600); 11 attachInterrupt(digitalPinToInterrupt(interruptPin), tacho, FALLING); 12} 13 14void loop() { 15 delay(500); 16 Serial.println(j); 17} 18 19void tacho() { 20 static unsigned long i; 21 j = micros() - i; 22 i = micros(); 23} 24
Main Program
c_cpp
1/* 2Arduino program for the Laser Projector Wall Clock 3 4Copyright 5 (C) 2016 Genny A. Carogna 6 7This program is free software: you can redistribute 8 it and/or modify 9it under the terms of the GNU General Public License as published 10 by 11the Free Software Foundation, either version 3 of the License, or 12(at your 13 option) any later version. 14 15This program is distributed in the hope that it 16 will be useful, 17but WITHOUT ANY WARRANTY; without even the implied warranty of 18MERCHANTABILITY 19 or FITNESS FOR A PARTICULAR PURPOSE. See the 20GNU General Public License for 21 more details. 22 23You should have received a copy of the GNU General Public License 24along 25 with this program. If not, see <http://www.gnu.org/licenses/>. 26*/ 27 28 29#include 30 <I2C.h> // you must install the "Arduino I2C Master Library" before 31 32#define 33 dOn PORTE=B00100000; // PE5 pin3 // dim tracts signal (clock face) 34#define 35 dOff PORTE=0; 36 37#define mOn PORTG=B00100000; // PG5 pin4 // medium intensity 38 tract signal (hours) 39#define mOff PORTG=0; 40 41#define bOn PORTH=B00001000; 42 // PH3 pin6 // full power (yeah!!) tracts signal (minutes and seconds) 43#define 44 bOff PORTH=0; 45 46#define dimPin 3 47#define mediumPin 4 48#define brightPin 49 6 50#define tachoPin 18 51 52#define qTractStart 0.1 // 1/12 turn "percentage" 53 // quadrant 54#define qTractEnd 0.9 55#define hTractStart 0.3 // 1/12 turn 56 "percentage" // hour arm 57#define hTractEnd 0.7 58 59#define loopPeriod 150 60 // milliseconds 61 62volatile unsigned int TurnPeriod = 65000; // this stores 63 the time necessary for an actual turn (in "16MHz /8" units) 64volatile bool reverse; 65 // this goes "1" during 11:XX and 00:XX 66 67volatile unsigned int ocr1a = 68 32000; 69//volatile unsigned int ocr3a = 32000; 70volatile unsigned int ocr4a 71 = 32000; 72//volatile unsigned int ocr5a = 32000; 73volatile unsigned int ocr1b 74 = 32000; 75volatile unsigned int ocr3b = 32000; 76volatile unsigned int ocr4b 77 = 32000; 78volatile unsigned int ocr5b = 32000; 79volatile unsigned int ocr1c 80 = 32000; 81volatile unsigned int ocr3c = 32000; 82volatile unsigned int ocr4c 83 = 32000; 84volatile unsigned int ocr5c = 32000; 85 86void setup(){ 87 pinMode(dimPin, 88 OUTPUT); 89 pinMode(mediumPin, OUTPUT); 90 pinMode(brightPin, OUTPUT); 91 92 93 attachInterrupt(digitalPinToInterrupt(tachoPin), tacho, FALLING); 94 95 I2c.begin(); 96 97 98 cli(); 99 TCCR0A = 0; // disabling disturbing (maybe) stuff, this disables 100 millis(), micros() and delay() 101 TCCR0B = 0; // 102 TIMSK0 = 0; // 103 104 105 //no prescaler for timer 1 106 TCCR1A = 0; 107 TCCR1B = 0; 108 TCCR1C = 0; 109 110 TIMSK1 = 0; 111 TCNT1 = 0; 112 OCR1A = 65000; 113 OCR1B = 30000; 114 OCR1C 115 = 20000; 116 TCCR1B |= (1 << WGM12); // CTC enabled only for timer1 117 TCCR1B 118 |= (1 << CS10); 119 //TIMSK1 |= (1 << OCIE1A); // we actually don't need an interrupt 120 on "1A" 121 TIMSK1 |= (1 << OCIE1B); 122 TIMSK1 |= (1 << OCIE1C); 123 124 // 125 /8 prescaler for others 126 TCCR3A = 0; 127 TCCR3B = 0; 128 TCCR3C = 0; 129 TIMSK3 130 = 0; 131 TCNT3 = 0; 132 OCR3A = 65000; 133 OCR3B = 64000; 134 OCR3C = 63000; 135 136 TCCR3B |= (1 << CS31); 137 //TIMSK3 |= (1 << OCIE3A); 138 TIMSK3 |= (1 << OCIE3B); 139 140 TIMSK3 |= (1 << OCIE3C); 141 142 TCCR4A = 0; 143 TCCR4B = 0; 144 TCCR4C = 0; 145 146 TIMSK4 = 0; 147 TCNT4 = 0; 148 OCR4A = 65000; 149 OCR4B = 64000; 150 OCR4C 151 = 63000; 152 TCCR4B |= (1 << CS41); 153 TIMSK4 |= (1 << OCIE4A); 154 TIMSK4 |= 155 (1 << OCIE4B); 156 TIMSK4 |= (1 << OCIE4C); 157 158 TCCR5A = 0; 159 TCCR5B = 160 0; 161 TCCR5C = 0; 162 TIMSK5 = 0; 163 TCNT5 = 0; 164 OCR5A = 65000; 165 OCR5B 166 = 64000; 167 OCR5C = 63000; 168 TCCR5B |= (1 << CS51); 169 //TIMSK5 |= (1 << 170 OCIE5A); 171 TIMSK5 |= (1 << OCIE5B); 172 TIMSK5 |= (1 << OCIE5C); 173 174 sei(); 175} 176 177void 178 loop(){ 179 // you can add stuff in loop(), like a way to set the time with buttons 180 181 182 for (byte i = 0; i < 100; i ++) { 183 delayMicroseconds(loopPeriod * 184 10); 185 } // only delayMicroseconds() works with timer0 disabled 186 187 I2c.read(0x68, 188 0x00, 3); 189 byte temp0 = I2c.receive(); 190 byte temp1 = temp0 >> 4; // with 191 Dallas RTCs time is stored as BCD (Binary Coded Decimal) 192 unsigned int seconds 193 = (temp1 * 10) + (temp0 & B00001111); // with Dallas RTCs time is stored as BCD 194 (Binary Coded Decimal) 195 196 temp0 = I2c.receive(); 197 temp1 = temp0 >> 4; 198 199 unsigned int minutes = (temp1 * 10) + (temp0 & B00001111); 200 201 temp0 = 202 I2c.receive(); 203 temp1 = temp0 >> 4; 204 unsigned int hours = (temp1 * 10) 205 + (temp0 & B00001111); 206 if (hours >= 12) hours -= 12; // lets keep it in 12 207 hours format 208 209 if(hours == 0 || hours == 11) { 210 reverse = 1; // for 211 having a contiguous track for the hours arm we reset timer3 at 6:00 position during 212 11:XX and 00:XX 213 } 214 else reverse = 0; 215 216 cli(); 217 unsigned int 218 turnPeriod = TurnPeriod; 219 sei(); 220 221 //A,B e C happen in reverse order 222 (CBA) 223 ocr1a = (turnPeriod / 3) * 2; // dim, end of the hour (turnPeriod / 224 12) * 8 225 226 //ocr3a = 227 228 ocr4a = turnPeriod / 2; // six o'clock 229 (used for the "reverse" case) 230 231 //ocr5a = 232 233 ocr1b = ocr1a * 234 qTractEnd; // dim, end of the drawn quadrant hour tract 235 236 ocr3b = (((turnPeriod 237 / 12) * hTractEnd) + ((turnPeriod / 720) * minutes)) - (turnPeriod / 24); // hours, 238 end of the drawn tract 239 if (hours == 0) ocr3b += turnPeriod / 2; // ((turnPeriod 240 / 12) * 6) 241 else if (hours == 11) ocr3b += (turnPeriod / 12) * 5; 242 else 243 ocr3b += (turnPeriod / 12) * hours; 244 245 float mRatioEnd = float(minutes + 246 1) / 60; 247 ocr4b = (turnPeriod * mRatioEnd); // minutes, end of the drawn tract 248 249 250 float sRatio = float(seconds) / 60; 251 ocr5b = (turnPeriod * sRatio) + 252 (turnPeriod / 80); // seconds, end of the drawn tract // (turnPeriod / (60 * 4)) 253 * 3 254 255 ocr1c = ocr1a * qTractStart; // dim, start of the drawn quadrant 256 hour tract 257 258 ocr3c = (((turnPeriod / 12) * hTractStart) + ((turnPeriod / 259 720) * minutes)) - (turnPeriod / 24); // hours, start of the drawn tract 260 if 261 (hours == 0) ocr3c += turnPeriod / 2; // ((turnPeriod / 12) * 6) 262 else if (hours 263 == 11) ocr3c += (turnPeriod / 12) * 5; 264 else ocr3c += (turnPeriod / 12) * hours; 265 266 267 float mRatioStart = float(minutes) / 60; 268 ocr4c = turnPeriod * mRatioStart; 269 // minutes, start of the drawn tract 270 if (ocr4c < 100) ocr4c = 100; // lets 271 try to NOT trigger a compare exactly when a timer resets and lets the "tacho" 272 do it's job 273 274 ocr5c = (turnPeriod * sRatio) + (turnPeriod / 240); // seconds, 275 start of the drawn tract // turnPeriod / (60 * 4) 276} 277 278void tacho() { 279 280 dOff 281 bOff 282 283 OCR1A = ocr1a; // refresh trigger points on various 284 timers 285 //OCR3A = ocr3a; // 286 OCR4A = ocr4a; // 287 //OCR5A = ocr5a; // 288 289 OCR1B = ocr1b; // 290 OCR3B = ocr3b; // 291 OCR4B = ocr4b; // 292 OCR5B 293 = ocr5b; // 294 OCR1C = ocr1c; // 295 OCR3C = ocr3c; // 296 OCR4C = ocr4c; 297 // 298 OCR5C = ocr5c; // 299 300 TurnPeriod = TCNT4; // read motor speed 301 for calculations 302 303 TCNT1 = 0; // restart timers 304 TCNT4 = 0; // 305 306 TCNT5 = 0; // 307 if (!reverse) { 308 TCNT3 = 0; // this in case we are 309 NOT at 11:XX or 00:XX 310 mOff 311 } 312} 313 314 315 316/* 317ISR(TIMER1_COMPA_vect){ 318 319} 320*/ 321ISR(TIMER1_COMPB_vect){ 322 323 dOff // comment this for reversed quadrant picture (small tracts at "o'clocks" 324 VS. big tracts into the hour span (default)) 325 //dOn // uncomment this for reversed 326 quadrant picture 327} 328 329ISR(TIMER1_COMPC_vect){ 330 dOn // comment this for 331 reversed quadrant picture 332 //dOff // uncomment this for reversed quadrant picture 333} 334 335 336/* 337ISR(TIMER3_COMPA_vect){ 338 339 340} 341*/ 342ISR(TIMER3_COMPB_vect){ 343 mOff // hour, end of the tract 344} 345 346ISR(TIMER3_COMPC_vect){ 347 348 mOn // hour, start of the tract 349} 350 351 352 353 354ISR(TIMER4_COMPA_vect){ 355 356 if (reverse) { // this in case we ARE at 11:XX or 00:XX 357 TCNT3 = 0; 358 359 mOff 360 } 361} 362 363ISR(TIMER4_COMPB_vect){ 364 bOff // minutes, end of 365 the tract 366} 367 368ISR(TIMER4_COMPC_vect){ 369 bOn // minutes, start of the 370 tract 371} 372 373 374 375/* 376ISR(TIMER5_COMPA_vect){ 377 378} 379*/ 380ISR(TIMER5_COMPB_vect){ 381 382 bOff // seconds, end of the tract 383} 384 385ISR(TIMER5_COMPC_vect){ 386 bOn 387 // seconds, start of the tract 388} 389
Program For Uploading Time On The RTC
c_cpp
1//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2//Sketch for uploading time on the RTC chip (adjust this sketch with 5 minutes more -> burn it -> disconnect the Arduino power 3//-> stick battery on the module -> connect the RTC to the board -> plug the USB at the exact time and open serial monitor)(don't connect it again) 4 5#include <Wire.h> 6 7void setup() { 8 Serial.begin(9600); 9 Wire.begin(); 10 11 Wire.beginTransmission(0x68); // address of the RTC (do not modify) 12 Wire.write(byte(0x00)); // address of the first data byte (seconds) (do not modify) 13 14 Wire.write(byte(0x00)); // seconds (from 0x00 to 0x59) 15 Wire.write(byte(0x30)); // minutes (from 0x00 to 0x59) 16 Wire.write(byte(0x10)); // hours (from 0x00 to 0x23) 17 Wire.write(byte(0x04)); // day of the week (from 0x01 to 0x07)(this is arbitrary) 18 Wire.write(byte(0x26)); // day of the month (from 0x01 to 0x31)(this is NOT arbitrary) 19 Wire.write(byte(0x05)); // month (from 0x01 to 0x12) 20 Wire.write(byte(0x16)); // year (from 0x00 to 0x99) 21 22 Wire.endTransmission(); 23} 24 25void loop() { 26 delay(1000); 27 28 Wire.beginTransmission(0x68); 29 Wire.write(byte(0x00)); 30 Wire.endTransmission(); 31 32 Wire.requestFrom(0x68, 7); 33 byte seconds = Wire.read(); 34 byte minutes = Wire.read(); 35 byte hours = Wire.read(); 36 byte dayWeek = Wire.read(); 37 byte dayMonth = Wire.read(); 38 byte month = Wire.read(); 39 byte year = Wire.read(); 40 41 Serial.print("Right now it's: "); 42 Serial.print(hours, HEX); 43 Serial.print(":"); 44 Serial.print(minutes, HEX); 45 Serial.print(":"); 46 Serial.println(seconds, HEX); 47 48 Serial.print("Today is day "); 49 Serial.print(dayWeek); 50 Serial.println(" of the week"); 51 52 Serial.print("Current date is: "); 53 Serial.print(dayMonth, HEX); 54 Serial.print("/"); 55 Serial.print(month, HEX); 56 Serial.print("/20"); 57 Serial.println(year, HEX); 58 Serial.println(); 59} 60
Downloadable files
General Schematic
General Schematic
General Schematic
General Schematic
Comments
Only logged in users can leave comments
screwpilot
0 Followers
•0 Projects
Table of contents
Intro
7
0