Design & schematics for ATTiny85, schematics for ATtiny85
This commit is contained in:
1
src/button.cpp
Normal file
1
src/button.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "button.hpp"
|
14
src/button.hpp
Normal file
14
src/button.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __BUTTON_HPP__
|
||||
#define __BUTTON_HPP__
|
||||
|
||||
#include "pins.hpp"
|
||||
|
||||
class Button {
|
||||
public:
|
||||
Button(unsigned analogPin = BTN_ANALOGPIN, int vRef = BTN_VREF) : _aPin{analogPin}, _vRef{vRef} {};
|
||||
private:
|
||||
unsigned _aPin;
|
||||
int _vRef;
|
||||
};
|
||||
|
||||
#endif /* __BUTTON_HPP__ */
|
34
src/display.cpp
Normal file
34
src/display.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "display.hpp"
|
||||
|
||||
Display::Display(int dataIn, int clk, int load) : _ledControler{dataIn, clk, load} {
|
||||
_ledControler.shutdown(0,false);
|
||||
/* Set the brightness to a medium values */
|
||||
_ledControler.setIntensity(0,8);
|
||||
/* and clear the display */
|
||||
_ledControler.clearDisplay(0);
|
||||
_ledControler.setDigit(0, 0, 0, false);
|
||||
_ledControler.setDigit(0, 1, 0, false);
|
||||
}
|
||||
|
||||
void Display::print_time(int seconds) {
|
||||
if (seconds < 60) {
|
||||
_ledControler.setDigit(0, 0, seconds % 10, false);
|
||||
_ledControler.setDigit(0, 1, seconds / 10, false);
|
||||
} else if (seconds < 600) {
|
||||
_ledControler.setDigit(0, 0, (seconds / 10) % 6, false);
|
||||
_ledControler.setDigit(0, 1, seconds / 60, true);
|
||||
} else {
|
||||
int minutes = seconds / 60;
|
||||
_ledControler.setDigit(0, 0, minutes % 10, true);
|
||||
_ledControler.setDigit(0, 1, minutes / 10, false);
|
||||
}
|
||||
}
|
||||
|
||||
void Display::chenillard(void) {
|
||||
for (size_t i = 0; i < 6; i++) {
|
||||
_ledControler.clearDisplay(0);
|
||||
_ledControler.setRow(0, 0, 1 << i);
|
||||
_ledControler.setRow(0, 1, 1 << i);
|
||||
delay(200);
|
||||
}
|
||||
}
|
17
src/display.hpp
Normal file
17
src/display.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef __DISPLAY_HPP__
|
||||
#define __DISPLAY_HPP__
|
||||
|
||||
#include <LedControl.h>
|
||||
|
||||
#include "pins.hpp"
|
||||
|
||||
class Display {
|
||||
public:
|
||||
Display(int dataIn = MAX_DATAIN, int clk = MAX_CLK, int load = MAX_LOAD);
|
||||
void print_time(int seconds);
|
||||
void chenillard(void);
|
||||
private:
|
||||
LedControl _ledControler;
|
||||
};
|
||||
|
||||
#endif /* __DISPLAY_HPP__ */
|
52
src/main.cpp
Normal file
52
src/main.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <Arduino.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// #include "display.hpp"
|
||||
// #include "rotary_encoder.hpp"
|
||||
|
||||
// int seconds = 0;
|
||||
//
|
||||
// void start_count(int seconds);
|
||||
//
|
||||
// Display display;
|
||||
// RotaryEncoder encoder;
|
||||
|
||||
SoftwareSerial swSerial(3, 4);
|
||||
|
||||
void setup() {
|
||||
swSerial.begin(9600);
|
||||
// display = Display();
|
||||
// encoder = RotaryEncoder();
|
||||
while(!swSerial.available());
|
||||
|
||||
swSerial.println("nik");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (analogRead(0) > 950) {
|
||||
swSerial.println("niki");
|
||||
} else {
|
||||
swSerial.println("pushed");
|
||||
}
|
||||
delay(1000);
|
||||
// display.print_time(seconds);
|
||||
// seconds = encoder.value_select(display);
|
||||
// start_count(seconds);
|
||||
// while (analogRead(0) > 950) {
|
||||
// display.chenillard();
|
||||
// }
|
||||
}
|
||||
|
||||
// void start_count(int secondsToWait) {
|
||||
// unsigned long millisToWait = secondsToWait * 1000L;
|
||||
// unsigned long millisElapsed = 0L;
|
||||
// unsigned long millisAtStart = millis();
|
||||
//
|
||||
// do {
|
||||
// millisElapsed = millis() - millisAtStart;
|
||||
// display.print_time(secondsToWait - millisElapsed / 1000);
|
||||
// delay(500);
|
||||
// } while (millisElapsed < millisToWait);
|
||||
//
|
||||
//
|
||||
// }
|
18
src/pins.hpp
Normal file
18
src/pins.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __PINS_HPP__
|
||||
#define __PINS_HPP__
|
||||
|
||||
/* MAX7219 */
|
||||
#define MAX_DATAIN 0
|
||||
#define MAX_CLK 2
|
||||
#define MAX_LOAD 1
|
||||
|
||||
/* Rotary Encoder */
|
||||
#define ENC_PINA 3
|
||||
#define ENC_PINB 4
|
||||
|
||||
|
||||
/* Button */
|
||||
#define BTN_ANALOGPIN 0
|
||||
#define BTN_VREF 4600
|
||||
|
||||
#endif /* __PINS_HPP__ */
|
59
src/rotary_encoder.cpp
Normal file
59
src/rotary_encoder.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "rotary_encoder.hpp"
|
||||
|
||||
int RotaryEncoder::value_select(Display &display) {
|
||||
int seconds{0};
|
||||
|
||||
while (analogRead(0) > 950) {
|
||||
int newEncVal{_encoder.read()};
|
||||
|
||||
if (newEncVal != _currentValue) {
|
||||
int increment{0};
|
||||
_shift += newEncVal - _currentValue;
|
||||
_currentValue = newEncVal;
|
||||
|
||||
if (-4 >= _shift || _shift >= 4) {
|
||||
int sign = _shift >> 2;
|
||||
|
||||
if (seconds < 60) {
|
||||
increment = 1 * sign;
|
||||
|
||||
if (seconds + increment < 0) {
|
||||
seconds = 5940;
|
||||
increment = 0;
|
||||
} else if (seconds + increment >= 60) {
|
||||
seconds = 60;
|
||||
increment = 0;
|
||||
}
|
||||
} else if (seconds < 600) {
|
||||
increment = sign * 10;
|
||||
|
||||
if (seconds + increment < 60) {
|
||||
seconds = 59;
|
||||
increment = 0;
|
||||
} else if (seconds + increment > 590) {
|
||||
seconds = 600;
|
||||
increment = 0;
|
||||
}
|
||||
} else {
|
||||
increment = sign * 60;
|
||||
|
||||
if (seconds + increment < 600) {
|
||||
seconds = 590;
|
||||
increment = 0;
|
||||
} else if (seconds + increment > 5940) {
|
||||
seconds = 0;
|
||||
increment = 0;
|
||||
}
|
||||
}
|
||||
|
||||
seconds += increment;
|
||||
|
||||
display.print_time(seconds);
|
||||
|
||||
_shift = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return seconds;
|
||||
}
|
18
src/rotary_encoder.hpp
Normal file
18
src/rotary_encoder.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __ROTARYENCODER_HPP__
|
||||
#define __ROTARYENCODER_HPP__
|
||||
|
||||
#include <encoder.h>
|
||||
|
||||
#include "display.hpp"
|
||||
#include "pins.hpp"
|
||||
|
||||
class RotaryEncoder {
|
||||
public:
|
||||
RotaryEncoder(uint8_t pinA = ENC_PINA, uint8_t pinB = ENC_PINB) : _encoder{pinA, pinB}, _currentValue{0}, _shift{0} {_encoder.write(0);};
|
||||
int value_select(Display &display);
|
||||
private:
|
||||
Encoder _encoder;
|
||||
int _currentValue, _shift;
|
||||
};
|
||||
|
||||
#endif /* __ROTARYENCODER_HPP__ */
|
160
src/uno_main.cpp.bak
Normal file
160
src/uno_main.cpp.bak
Normal file
@@ -0,0 +1,160 @@
|
||||
#include <Arduino.h>
|
||||
#include <LedControl.h>
|
||||
#include <Encoder.h>
|
||||
|
||||
/*
|
||||
pin 0 is connected to the DataIn
|
||||
pin 2 is connected to the CLK
|
||||
pin 1 is connected to LOAD
|
||||
We have only a single MAX72XX.
|
||||
*/
|
||||
#if BUILD_ENV_NAME == uno
|
||||
LedControl lc = LedControl(11, 13, 10, 1);
|
||||
#else
|
||||
LedControl lc = LedControl(0, 2, 1, 1)
|
||||
#endif
|
||||
|
||||
Encoder myEnc(3, 4);
|
||||
int encVal = 0;
|
||||
int shift = 0;
|
||||
|
||||
int seconds = 0;
|
||||
|
||||
void print_time(int seconds);
|
||||
|
||||
void value_select(void);
|
||||
|
||||
void start_count(int seconds);
|
||||
|
||||
void setup() {
|
||||
lc.shutdown(0,false);
|
||||
/* Set the brightness to a medium values */
|
||||
lc.setIntensity(0,8);
|
||||
/* and clear the display */
|
||||
lc.clearDisplay(0);
|
||||
lc.setDigit(0, 0, 0, false);
|
||||
lc.setDigit(0, 1, 0, false);
|
||||
|
||||
myEnc.write(0);
|
||||
|
||||
#if BUILD_ENV_NAME == uno
|
||||
Serial.begin(115200);
|
||||
while(!Serial.available());
|
||||
Serial.print("BUILD_ENV_NAME : ");
|
||||
Serial.println(BUILD_ENV_NAME);
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
print_time(seconds);
|
||||
while (analogRead(0) > 950) {
|
||||
value_select();
|
||||
}
|
||||
start_count(seconds);
|
||||
}
|
||||
|
||||
void value_select(void) {
|
||||
int newEncVal = myEnc.read();
|
||||
if (newEncVal != encVal) {
|
||||
int increment = 0;
|
||||
shift += newEncVal - encVal;
|
||||
encVal = newEncVal;
|
||||
|
||||
if (-4 >= shift || shift >= 4) {
|
||||
int sign = shift >> 2;
|
||||
|
||||
if (seconds < 60) {
|
||||
increment = 1 * sign;
|
||||
|
||||
if (seconds + increment < 0) {
|
||||
seconds = 5940;
|
||||
increment = 0;
|
||||
} else if (seconds + increment >= 60) {
|
||||
seconds = 60;
|
||||
increment = 0;
|
||||
}
|
||||
} else if (seconds < 600) {
|
||||
increment = sign * 10;
|
||||
|
||||
if (seconds + increment < 60) {
|
||||
seconds = 59;
|
||||
increment = 0;
|
||||
} else if (seconds + increment > 590) {
|
||||
seconds = 600;
|
||||
increment = 0;
|
||||
}
|
||||
} else {
|
||||
increment = sign * 60;
|
||||
|
||||
if (seconds + increment < 600) {
|
||||
seconds = 590;
|
||||
increment = 0;
|
||||
} else if (seconds + increment > 5940) {
|
||||
seconds = 0;
|
||||
increment = 0;
|
||||
}
|
||||
}
|
||||
|
||||
seconds += increment;
|
||||
|
||||
print_time(seconds);
|
||||
|
||||
shift = 0;
|
||||
|
||||
#if BUILD_ENV_NAME == uno
|
||||
Serial.print("Seconds : ");
|
||||
Serial.println(seconds, DEC);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void start_count(int secondsToWait) {
|
||||
unsigned long millisToWait = secondsToWait * 1000L;
|
||||
unsigned long millisElapsed = 0L;
|
||||
unsigned long millisAtStart = millis();
|
||||
|
||||
do {
|
||||
millisElapsed = millis() - millisAtStart;
|
||||
print_time(secondsToWait - millisElapsed / 1000);
|
||||
delay(500);
|
||||
#if BUILD_ENV_NAME == uno
|
||||
Serial.print("millisElapsed : ");
|
||||
Serial.print(millisElapsed, DEC);
|
||||
Serial.print(" / ");
|
||||
Serial.print(millisToWait, DEC);
|
||||
Serial.print(" (");
|
||||
Serial.print(secondsToWait * 1000, DEC);
|
||||
Serial.println(") ");
|
||||
Serial.print("Remaining time : ");
|
||||
Serial.print(secondsToWait - millisElapsed / 1000, DEC);
|
||||
Serial.println(" s");
|
||||
#endif
|
||||
} while (millisElapsed < millisToWait);
|
||||
|
||||
while (analogRead(0) > 950) {
|
||||
lc.setChar(0, 0, '-', false);
|
||||
lc.setChar(0, 1, '-', false);
|
||||
delay(300);
|
||||
lc.setChar(0, 0, ' ', false);
|
||||
lc.setChar(0, 1, ' ', false);
|
||||
delay(300);
|
||||
}
|
||||
|
||||
while (analogRead(0) < 950) {
|
||||
}
|
||||
}
|
||||
|
||||
void print_time(int seconds) {
|
||||
if (seconds < 60) {
|
||||
lc.setDigit(0, 0, seconds % 10, false);
|
||||
lc.setDigit(0, 1, seconds / 10, false);
|
||||
} else if (seconds < 600) {
|
||||
lc.setDigit(0, 0, (seconds / 10) % 6, false);
|
||||
lc.setDigit(0, 1, seconds / 60, true);
|
||||
} else {
|
||||
int minutes = seconds / 60;
|
||||
lc.setDigit(0, 0, minutes % 10, true);
|
||||
lc.setDigit(0, 1, minutes / 10, false);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user