Added some Comments
This commit is contained in:
parent
ee496d4702
commit
48531bb1bd
|
@ -1,6 +1,8 @@
|
|||
#include "DigiKeyboard.h"
|
||||
#include <EEPROM.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 address 0
|
||||
|
|
|
@ -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
|
||||
|
||||
//pins for hour display
|
||||
const unsigned char H[] = {8,9,10,11};
|
||||
//pins for min display
|
||||
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 = 59500;
|
||||
|
||||
//current time
|
||||
unsigned char min = 0;
|
||||
unsigned char hour = 0;
|
||||
|
||||
//last time the minute changed
|
||||
unsigned long lastmin;
|
||||
|
||||
//remove this line to enable Serial
|
||||
#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) {
|
||||
//write minutes
|
||||
for(unsigned char i = 0; i < 6; i++) {
|
||||
analogWrite(M[i], (m & (1 << i)) ? 255 : 1);
|
||||
}
|
||||
|
||||
//write hour
|
||||
for(unsigned char i = 0; i < 4; i++) {
|
||||
analogWrite(H[i], (h & (1 << i)) ? 255 : 4);
|
||||
}
|
||||
#ifndef nolog
|
||||
//send data to Serial
|
||||
Serial.print(hour);
|
||||
Serial.print(":");
|
||||
Serial.println(min);
|
||||
#endif
|
||||
}
|
||||
|
||||
//add one minute to the time
|
||||
void countTime() {
|
||||
if(60 == ++min) {
|
||||
min = 0;
|
||||
|
@ -56,19 +72,19 @@ void setup() {
|
|||
while(!pressed) delay(5);
|
||||
|
||||
//setup time
|
||||
char mode = 0;
|
||||
bool pres = false;
|
||||
char mode = 0;//mode = 0-> set hour, mode = 1 -> set min, mode = 2 -> exit setup
|
||||
bool pres = false;//was button pressed
|
||||
unsigned long timeout = millis();
|
||||
while(mode < 2) {
|
||||
if(pressed) {//button is pressed
|
||||
if(!pres) {//button was not pressed before
|
||||
timeout = millis();
|
||||
timeout = millis();//reset timeout
|
||||
pres = true;
|
||||
if(mode == 0) {
|
||||
if(mode == 0) {//count hour
|
||||
hour ++;
|
||||
if(hour == 13)
|
||||
hour = 1;
|
||||
} else {
|
||||
} else {//count min
|
||||
min ++;
|
||||
if(min == 60)
|
||||
min = 0;
|
||||
|
@ -78,7 +94,8 @@ void setup() {
|
|||
} else {
|
||||
pres = false;
|
||||
}
|
||||
if(millis() - timeout > 10000) {
|
||||
if(millis() - timeout > 10000) {//timed out
|
||||
//blink 6 times
|
||||
for(int i = 0; i < 6; i++) {
|
||||
write(0,0);
|
||||
delay(300);
|
||||
|
@ -86,7 +103,8 @@ void setup() {
|
|||
delay(300);
|
||||
}
|
||||
write(min, hour);
|
||||
++mode;
|
||||
++mode;//next mode
|
||||
//reset timeout
|
||||
timeout = millis();
|
||||
}
|
||||
delay(50);
|
||||
|
@ -107,6 +125,7 @@ void loop() {
|
|||
Serial.println(millis()-lastmin >= mindelay);
|
||||
#endif
|
||||
}
|
||||
//let the led blink
|
||||
if(millis()/1000 % 2 == 0) {
|
||||
digitalWrite(13, HIGH);
|
||||
} else
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
/*
|
||||
* author: MrBesen
|
||||
* A unfinished program to draw text with a laser to the wall.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Servo.h>
|
||||
|
||||
#define MOTOR_X 6
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
//code to create a 1 Hz pulse signal
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(13, OUTPUT);
|
||||
pinMode(130, OUTPUT);
|
||||
pinMode(10, OUTPUT);
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
|
|
Loading…
Reference in New Issue