Added some Comments

This commit is contained in:
MrBesen 2018-10-29 08:20:04 +01:00
parent ee496d4702
commit 48531bb1bd
4 changed files with 39 additions and 10 deletions

View File

@ -1,6 +1,8 @@
#include "DigiKeyboard.h" #include "DigiKeyboard.h"
#include <EEPROM.h> #include <EEPROM.h>
//https://github.com/digistump/DigisparkArduinoIntegration/blob/master/libraries/DigisparkKeyboard/DigiKeyboard.h //https://github.com/digistump/DigisparkArduinoIntegration/blob/master/libraries/DigisparkKeyboard/DigiKeyboard.h
//Boardmanager URL: http://digistump.com/package_digistump_index.json
//#define LED_BUILTIN 1 //#define LED_BUILTIN 1
#define address 0 #define address 0

View File

@ -1,35 +1,51 @@
/*
* author: MrBesen
*
* Program for a binary laser clock
*
* Setup: a Button on pin 12, Led pin 13, Laser / LED on pin 2-11 needs to be pwm!
*
*/
#define pressed digitalRead(12) == LOW #define pressed digitalRead(12) == LOW
//pins for hour display
const unsigned char H[] = {8,9,10,11}; const unsigned char H[] = {8,9,10,11};
//pins for min display
const unsigned char M[] = {2,3,4,5,6,7}; const unsigned char M[] = {2,3,4,5,6,7};
//how long takes a minute in ms?
//const unsigned int mindelay = 60000; //const unsigned int mindelay = 60000;
const unsigned int mindelay = 59500; const unsigned int mindelay = 59500;
//current time
unsigned char min = 0; unsigned char min = 0;
unsigned char hour = 0; unsigned char hour = 0;
//last time the minute changed
unsigned long lastmin; unsigned long lastmin;
//remove this line to enable Serial
#define nolog #define nolog
//prints the data to the lasers, write(0,0)-> all off, write()-> all on
void write(unsigned char m = 255, unsigned char h = 255) { void write(unsigned char m = 255, unsigned char h = 255) {
//write minutes //write minutes
for(unsigned char i = 0; i < 6; i++) { for(unsigned char i = 0; i < 6; i++) {
analogWrite(M[i], (m & (1 << i)) ? 255 : 1); analogWrite(M[i], (m & (1 << i)) ? 255 : 1);
} }
//write hour
for(unsigned char i = 0; i < 4; i++) { for(unsigned char i = 0; i < 4; i++) {
analogWrite(H[i], (h & (1 << i)) ? 255 : 4); analogWrite(H[i], (h & (1 << i)) ? 255 : 4);
} }
#ifndef nolog #ifndef nolog
//send data to Serial
Serial.print(hour); Serial.print(hour);
Serial.print(":"); Serial.print(":");
Serial.println(min); Serial.println(min);
#endif #endif
} }
//add one minute to the time
void countTime() { void countTime() {
if(60 == ++min) { if(60 == ++min) {
min = 0; min = 0;
@ -56,19 +72,19 @@ void setup() {
while(!pressed) delay(5); while(!pressed) delay(5);
//setup time //setup time
char mode = 0; char mode = 0;//mode = 0-> set hour, mode = 1 -> set min, mode = 2 -> exit setup
bool pres = false; bool pres = false;//was button pressed
unsigned long timeout = millis(); unsigned long timeout = millis();
while(mode < 2) { while(mode < 2) {
if(pressed) {//button is pressed if(pressed) {//button is pressed
if(!pres) {//button was not pressed before if(!pres) {//button was not pressed before
timeout = millis(); timeout = millis();//reset timeout
pres = true; pres = true;
if(mode == 0) { if(mode == 0) {//count hour
hour ++; hour ++;
if(hour == 13) if(hour == 13)
hour = 1; hour = 1;
} else { } else {//count min
min ++; min ++;
if(min == 60) if(min == 60)
min = 0; min = 0;
@ -78,7 +94,8 @@ void setup() {
} else { } else {
pres = false; pres = false;
} }
if(millis() - timeout > 10000) { if(millis() - timeout > 10000) {//timed out
//blink 6 times
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
write(0,0); write(0,0);
delay(300); delay(300);
@ -86,7 +103,8 @@ void setup() {
delay(300); delay(300);
} }
write(min, hour); write(min, hour);
++mode; ++mode;//next mode
//reset timeout
timeout = millis(); timeout = millis();
} }
delay(50); delay(50);
@ -107,6 +125,7 @@ void loop() {
Serial.println(millis()-lastmin >= mindelay); Serial.println(millis()-lastmin >= mindelay);
#endif #endif
} }
//let the led blink
if(millis()/1000 % 2 == 0) { if(millis()/1000 % 2 == 0) {
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
} else } else

View File

@ -1,3 +1,9 @@
/*
* author: MrBesen
* A unfinished program to draw text with a laser to the wall.
*
*/
#include <Servo.h> #include <Servo.h>
#define MOTOR_X 6 #define MOTOR_X 6

View File

@ -1,7 +1,9 @@
//code to create a 1 Hz pulse signal
void setup() { void setup() {
pinMode(13, OUTPUT); pinMode(13, OUTPUT);
pinMode(130, OUTPUT); pinMode(10, OUTPUT);
} }
// the loop function runs over and over again forever // the loop function runs over and over again forever