Design & schematics for ATTiny85, schematics for ATtiny85

This commit is contained in:
Tropicananass 2019-11-06 13:52:44 +01:00
parent 326d4eb15d
commit 64e667a698
20 changed files with 30172 additions and 0 deletions

39
include/README Normal file
View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
lib/README Normal file
View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

27
platformio.ini Normal file
View File

@ -0,0 +1,27 @@
;PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = attiny85
[env]
build_flags = -D BUILD_ENV_NAME=$PIOENV
[env:attiny85]
platform = atmelavr
board = attiny85
framework = arduino
upload_protocol = usbtiny
board_build.f_cpu = 1000000L
[env:uno]
platform = atmelavr
board = uno
framework = arduino

29676
res/Atmel_attiny84.pdf Normal file

File diff suppressed because one or more lines are too long

BIN
res/Atmel_attiny85.pdf Normal file

Binary file not shown.

BIN
res/MAX7219-MAX7221.pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

1
src/button.cpp Normal file
View File

@ -0,0 +1 @@
#include "button.hpp"

14
src/button.hpp Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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);
}
}

11
test/README Normal file
View File

@ -0,0 +1,11 @@
This directory is intended for PIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html