mirror of
https://github.com/DinoMalin/paranoia-1.0.git
synced 2025-10-29 03:05:59 +00:00
feat: jauge
This commit is contained in:
parent
fb7b3bbe01
commit
1cf9ee307a
12
Makefile
12
Makefile
@ -1,10 +1,10 @@
|
||||
all: compile upload
|
||||
|
||||
compile:
|
||||
arduino-cli compile --fqbn arduino:mbed_nano:nano33ble sketch
|
||||
arduino-cli compile --fqbn arduino:avr:uno sketch
|
||||
|
||||
upload:
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:mbed_nano:nano33ble sketch
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno sketch
|
||||
|
||||
listen:
|
||||
bash listen.sh
|
||||
@ -12,3 +12,11 @@ listen:
|
||||
env:
|
||||
bash --rcfile env.sh
|
||||
|
||||
jauge: compile-jauge upload_jauge
|
||||
|
||||
compile-jauge:
|
||||
arduino-cli compile --fqbn arduino:avr:uno jauge
|
||||
|
||||
upload_jauge:
|
||||
arduino-cli upload -p /dev/ttyUSB0 --fqbn arduino:avr:uno jauge
|
||||
|
||||
|
||||
10
jauge/Jauge.h
Normal file
10
jauge/Jauge.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "LCD.h"
|
||||
|
||||
class Jauge {
|
||||
private:
|
||||
LCD lcd;
|
||||
public:
|
||||
Jauge(LCD lcd);
|
||||
void update(int newScore);
|
||||
};
|
||||
13
jauge/Jauge.ino
Normal file
13
jauge/Jauge.ino
Normal file
@ -0,0 +1,13 @@
|
||||
#include "Jauge.h"
|
||||
|
||||
Jauge::Jauge(LCD _lcd) : lcd(_lcd) {}
|
||||
|
||||
void Jauge::update(int newScore) {
|
||||
lcd.clear();
|
||||
for (int i = 0; i < newScore*2; i++) {
|
||||
lcd.drawRectangle(i, 0);
|
||||
lcd.drawRectangle(i+1, 0);
|
||||
lcd.drawRectangle(i,1);
|
||||
lcd.drawRectangle(i+1, 1);
|
||||
}
|
||||
}
|
||||
17
jauge/LCD.h
Normal file
17
jauge/LCD.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <Wire.h>
|
||||
#include <hd44780.h>
|
||||
#include <hd44780ioClass/hd44780_I2Cexp.h>
|
||||
|
||||
class LCD {
|
||||
private:
|
||||
hd44780_I2Cexp *lcd;
|
||||
public:
|
||||
LCD(hd44780_I2Cexp *lcd);
|
||||
|
||||
void drawChar(int x, int y, char c);
|
||||
void drawRectangle(int x, int y);
|
||||
void drawBlink(int x, int y);
|
||||
void clear();
|
||||
};
|
||||
17
jauge/LCD.ino
Normal file
17
jauge/LCD.ino
Normal file
@ -0,0 +1,17 @@
|
||||
#include "LCD.h"
|
||||
|
||||
LCD::LCD(hd44780_I2Cexp *_lcd) : lcd(_lcd) {}
|
||||
|
||||
void LCD::drawChar(int x, int y, char c) {
|
||||
lcd->setCursor(x,y);
|
||||
int w = lcd->write(byte(c));
|
||||
}
|
||||
|
||||
void LCD::drawRectangle(int x, int y) {
|
||||
drawChar(x, y, 0);
|
||||
}
|
||||
void LCD::drawBlink(int x, int y) {
|
||||
drawChar(x, y, 1);
|
||||
}
|
||||
|
||||
void LCD::clear() {lcd->clear();}
|
||||
12
jauge/characters.h
Normal file
12
jauge/characters.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
extern byte rectangle[8];
|
||||
extern byte blink[8];
|
||||
|
||||
extern byte angryL[8];
|
||||
extern byte angryR[8];
|
||||
|
||||
extern byte Heart1[8];
|
||||
extern byte Heart2[8];
|
||||
extern byte Heart3[8];
|
||||
extern byte Heart4[8];
|
||||
88
jauge/characters.ino
Normal file
88
jauge/characters.ino
Normal file
@ -0,0 +1,88 @@
|
||||
#include "characters.h"
|
||||
|
||||
byte rectangle[8] = {
|
||||
0xff,
|
||||
0xff,
|
||||
0xff,
|
||||
0xff,
|
||||
0xff,
|
||||
0xff,
|
||||
0xff,
|
||||
0xff,
|
||||
};
|
||||
|
||||
byte blink[8] = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0b11111,
|
||||
0b11111,
|
||||
};
|
||||
|
||||
byte angryL[8] = {
|
||||
0b10000,
|
||||
0b11000,
|
||||
0b11100,
|
||||
0b11110,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
};
|
||||
|
||||
byte angryR[8] = {
|
||||
0b00001,
|
||||
0b00011,
|
||||
0b00111,
|
||||
0b01111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
};
|
||||
|
||||
byte Heart1[8] = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0b01100,
|
||||
0b11110,
|
||||
0b11111,
|
||||
0b11111,
|
||||
};
|
||||
|
||||
byte Heart2[8] = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0b00110,
|
||||
0b01111,
|
||||
0b11111,
|
||||
0b11111,
|
||||
};
|
||||
|
||||
byte Heart3[8] = {
|
||||
0b01111,
|
||||
0b00111,
|
||||
0b00011,
|
||||
0b00001,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
byte Heart4[8] = {
|
||||
0b11110,
|
||||
0b11100,
|
||||
0b11000,
|
||||
0b10000,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
23
jauge/jauge.ino
Normal file
23
jauge/jauge.ino
Normal file
@ -0,0 +1,23 @@
|
||||
#include "Jauge.h"
|
||||
#include "characters.h"
|
||||
|
||||
hd44780_I2Cexp lcd;
|
||||
LCD _lcd(&lcd);
|
||||
Jauge jauge(_lcd);
|
||||
|
||||
void setup() {
|
||||
lcd.begin(16, 2);
|
||||
lcd.createChar(0, rectangle);
|
||||
Serial.begin(9600);
|
||||
jauge.update(5);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available() > 0) {
|
||||
char c = Serial.read();
|
||||
|
||||
if (c >= '0' && c <= '8') {
|
||||
jauge.update(c - '0');
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user