/*
MIT License
Copyright (c) 2016-2021, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
Attiny85 PINS
____
RESET -|_| |- 3V
SCL (3) -| |- (2)
SDA (4) -| |- (1)
GND -|____|- (0)
Atmega328 PINS: connect LCD to A4/A5
*/
#include "lcdgfx.h"
const uint8_t Owl [] PROGMEM = {0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0x30, 0x18, 0x0C, 0x0C, 0x0E, 0x0E, 0x0E, 0x1E, 0x3F, 0xFF,
0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xEC, 0xA0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x7C, 0x7F, 0x7F, 0x7F, 0x7F, 0x7C, 0x70, 0x70, 0x60, 0x60, 0x60, 0x70, 0x78, 0x7C, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7D, 0x7D, 0x6D, 0x6C, 0x60, 0x60, 0x60, 0x60, 0x40,
0x02, 0x3E, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0x7E, 0x7E, 0x3E, 0x3E, 0x36, 0x36, 0x06, 0x06, 0x06, 0x02,
0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x0F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF,
0xFF, 0xFF, 0x7F, 0x1F, 0x1F, 0x1F, 0x0F, 0x07, 0x07, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00
};
DisplaySSD1306_128x64_I2C display(-1); // or (-1,{busId, addr, scl, sda, frequency})
//DisplaySSD1306_128x64_SPI display(-1,{-1, 0, 1, 0, -1, -1}); // Use this line for nano pi (RST not used, 0=CE, gpio1=D/C)
//DisplaySSD1306_128x64_SPI display(3,{-1, 4, 5, 0,-1,-1}); // Use this line for Atmega328p (3=RST, 4=CE, 5=D/C)
//DisplayST7735_128x160x16_SPI display(3,{-1, 4, 5, 0,-1,-1});
//DisplaySSD1306_128x64_SPI display(24,{-1, 0, 23, 0,-1,-1}); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
//DisplaySSD1306_128x64_SPI display(22,{-1, 5, 21, 0,-1,-1}); // Use this line for ESP32 (VSPI) (gpio22=RST, gpio5=CE for VSPI, gpio21=D/C)
char buffer [2];
byte chargeur = 40;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 100;
const int butPin = A0;
const int butAnimPin = A1;
byte animation = 0;
bool modeAffichage = 1;
//byte animationP = 40;
boolean animationIncrease = true;
NanoCanvas<64, 64, 1> canvas;
NanoCanvas<20, 40, 1> canvasP;
void setup()
{
pinMode(butPin, INPUT);
pinMode(butAnimPin, INPUT);
display.begin();
display.clear();
display.setFixedFont( ssd1306xled_font6x8 );
display.drawBitmap1(94, 32, 32, 32, Owl);
canvas.clear();
canvas.setColor( 0xFF );
canvasP.setColor( 0xFF );
canvasP.clear();
canvasP.fillRect(2, 64, 22, - 40);
display.drawCanvas(64, 24, canvasP);
display.printFixedN (64, 0, "E-11", STYLE_NORMAL, 1);
// display.printFixed (0, 16, "Line 2. Bold text", STYLE_BOLD);
// display.printFixed (0, 24, "Line 3. Italic text", STYLE_ITALIC);
//afficheChargeur();
}
void loop()
{
if (analogRead(butPin) < 100) {
chargeur--;
//tir(5);
//delay(500);
//afficheBar();
}
if ((millis() - lastDebounceTime) > debounceDelay && chargeur < 40) {
lastDebounceTime = millis();
chargeur++;
//TODO if mode numerique
//afficheChargeur();
//afficheBar();
}
if (analogRead(butAnimPin) < 100) {
if (modeAffichage == 0) {
modeAffichage = 1;
display.clear();
}
afficheChargeur();
}
else {
if (modeAffichage == 1) {
display.clear();
display.drawBitmap1(94, 32, 32, 32, Owl);
modeAffichage = 0;
}
drawScanner();
display.drawCanvas(0, 0, canvas);
afficheBar();
}
}
void afficheBar() {
canvasP.clear();
canvasP.fillRect(2, 64, 22, 40 - chargeur);
display.drawCanvas(64, 24, canvasP);
}
void drawScanner() {
canvas.clear();
canvas.drawVLine(32, 0, 64);
canvas.drawHLine(0, 32, 64);
canvas.drawVLine(8, 29, 35);
canvas.drawVLine(16, 29, 35);
canvas.drawVLine(24, 29, 35);
canvas.drawVLine(40, 29, 35);
canvas.drawVLine(48, 29, 35);
canvas.drawVLine(56, 29, 35);
canvas.drawHLine(29, 8, 35);
canvas.drawHLine(29, 16, 35);
canvas.drawHLine(29, 24, 35);
canvas.drawHLine(29, 40, 35);
canvas.drawHLine(29, 48, 35);
canvas.drawHLine(29, 56, 35);
canvas.drawCircle(32, 32, animation);
animation++;
if (animation > 32) {
animation = 0;
}
}
void tir(byte coup) {
while (coup > 0 && chargeur > 0)
{
coup--;
chargeur--;
afficheChargeur();
//delay(100);
}
}
void afficheChargeur() {
if (chargeur <= 0) {
display.setFixedFont(ssd1306xled_font8x16);
display.fill(0x00);
display.printFixedN(10, 0, "LOW", STYLE_NORMAL, 2);
delay(1000);
} else
//display.fill(0x00); //TODO optimiser
display.setFixedFont(digital_font5x7_123);
if (chargeur < 10)
{
buffer[0] = '0';
buffer[1] = chargeur + '0';
display.printFixedN (10, 0, buffer, STYLE_NORMAL, 3);
}
else
display.printFixedN (10, 0, itoa(chargeur, buffer, 10), STYLE_NORMAL, 3);
}