clean things up a bit
parent
1da249ad69
commit
6aa6e37413
|
@ -0,0 +1,44 @@
|
|||
#include "buzzer.h"
|
||||
#include "constants.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
void buzzOff() {
|
||||
noTone(BUZZER_PIN);
|
||||
pinMode(BUZZER_PIN, INPUT);
|
||||
}
|
||||
|
||||
void helloBuzz() {
|
||||
tone(BUZZER_PIN, 500, 100);
|
||||
delay(100);
|
||||
tone(BUZZER_PIN, 1000, 100);
|
||||
delay(100);
|
||||
tone(BUZZER_PIN, 4000, 100);
|
||||
delay(100);
|
||||
buzzOff();
|
||||
}
|
||||
|
||||
void happyBuzz() {
|
||||
tone(BUZZER_PIN, 1500, 50);
|
||||
delay(75);
|
||||
tone(BUZZER_PIN, 2000, 100);
|
||||
delay(100);
|
||||
buzzOff();
|
||||
}
|
||||
|
||||
void sadBuzz() {
|
||||
tone(BUZZER_PIN, 330, 250);
|
||||
delay(300);
|
||||
tone(BUZZER_PIN, 311, 250);
|
||||
delay(250);
|
||||
buzzOff();
|
||||
}
|
||||
|
||||
void beep() {
|
||||
tone(BUZZER_PIN, 1000, 50);
|
||||
delay(50);
|
||||
buzzOff();
|
||||
}
|
||||
|
||||
void tick() {
|
||||
tone(BUZZER_PIN, 200, 5);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
void helloBuzz();
|
||||
void happyBuzz();
|
||||
void sadBuzz();
|
||||
void beep();
|
||||
void buzzOff();
|
||||
void tick();
|
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
// --- debug config
|
||||
|
||||
#define DEBUG_I2C 0
|
||||
|
||||
// --- pinout
|
||||
|
||||
#define LED_PIN LED_BUILTIN
|
||||
|
||||
#define BUZZER_PIN 11
|
||||
|
||||
// rotary encoder
|
||||
#define CLK_PIN 7
|
||||
#define DT_PIN 6
|
||||
#define SW_PIN 5
|
||||
|
||||
// --- LCD config
|
||||
|
||||
#define LCD_I2C_ADDR 0x27
|
||||
#define LCD_COLS 16
|
||||
#define LCD_ROWS 2
|
||||
|
||||
// --- Keyboard config
|
||||
|
||||
#define KBD_I2C_ADDR 0x21
|
|
@ -0,0 +1,24 @@
|
|||
#include <Arduino.h>
|
||||
#include "constants.h"
|
||||
|
||||
#if DEBUG_I2C
|
||||
#include <I2CScanner.h>
|
||||
|
||||
I2CScanner scanner;
|
||||
#endif
|
||||
|
||||
void setupDebug() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.println("it's cewk-o-mator, hello!");
|
||||
#if DEBUG_I2C
|
||||
scanner.Init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void debugScanI2C() {
|
||||
#if DEBUG_I2C
|
||||
scanner.Scan();
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
void setupDebug();
|
||||
void debugScanI2C();
|
|
@ -0,0 +1,32 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
/*
|
||||
|
||||
SW - Switch, goes low when pressed
|
||||
|
||||
CLK and DT from high to low, and so on when rotated
|
||||
|
||||
When rotated clockwise, CLK changes before DT; when rotated counter-clockwise, DT changes before CLK
|
||||
|
||||
*/
|
||||
|
||||
void setupEncoder() {
|
||||
pinMode(CLK_PIN, INPUT);
|
||||
pinMode(DT_PIN, INPUT);
|
||||
pinMode(SW_PIN, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void demoEncoder() {
|
||||
bool clk = digitalRead(CLK_PIN);
|
||||
bool dt = digitalRead(DT_PIN);
|
||||
bool sw = digitalRead(SW_PIN);
|
||||
|
||||
Serial.print("CLK: ");
|
||||
Serial.print(clk);
|
||||
Serial.print(" DT: ");
|
||||
Serial.print(dt);
|
||||
Serial.print(" SW: ");
|
||||
Serial.println(sw);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
void setupEncoder();
|
||||
void demoEncoder();
|
|
@ -0,0 +1,27 @@
|
|||
#include <PCF8574.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
PCF8574 kbd(KBD_I2C_ADDR, &Wire);
|
||||
|
||||
bool setupKeyboard() {
|
||||
if (!kbd.begin()) {
|
||||
Serial.println("Could not initialize keyboard");
|
||||
return false;
|
||||
}
|
||||
if (!kbd.isConnected()) {
|
||||
Serial.println("Keyboard not connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void demoKeyboard() {
|
||||
kbd.write8(0b11110000); // first 4 bits are columns, low when pressed
|
||||
// kbd.write8(0b00001111); // last 4 bits are rows, low when pressed
|
||||
int x = kbd.read8();
|
||||
Serial.print("Keyboard: ");
|
||||
Serial.println(x, BIN);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
bool setupKeyboard();
|
||||
void demoKeyboard();
|
|
@ -1,92 +1,32 @@
|
|||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <LCD_I2C.h>
|
||||
// #include <I2C_Scanner.h>
|
||||
#include <I2CScanner.h>
|
||||
#include <PCF8574.h>
|
||||
|
||||
#define BUZZER_PIN 11
|
||||
|
||||
// when rotated clockwise, CLK changes before DT
|
||||
#define CLK_PIN 7
|
||||
#define DT_PIN 6
|
||||
#define SW_PIN 5 // switch, goes low when pressed
|
||||
|
||||
I2CScanner scanner;
|
||||
|
||||
LCD_I2C lcd(0x27, 16, 2);
|
||||
PCF8574 PCF(0x21, &Wire);
|
||||
|
||||
void helloBuzz();
|
||||
#include "constants.h"
|
||||
#include "buzzer.h"
|
||||
#include "screen.h"
|
||||
#include "keyboard.h"
|
||||
#include "encoder.h"
|
||||
#include "debug.h"
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
pinMode(CLK_PIN, INPUT);
|
||||
pinMode(DT_PIN, INPUT);
|
||||
pinMode(SW_PIN, INPUT_PULLUP);
|
||||
setupDebug();
|
||||
setupEncoder();
|
||||
|
||||
Wire.begin();
|
||||
scanner.Init();
|
||||
|
||||
lcd.begin();
|
||||
lcd.backlight();
|
||||
setupScreen();
|
||||
setupKeyboard();
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.println("Hello World!");
|
||||
helloBuzz();
|
||||
|
||||
if (!PCF.begin())
|
||||
{
|
||||
Serial.println("could not initialize...");
|
||||
}
|
||||
if (!PCF.isConnected())
|
||||
{
|
||||
Serial.println("=> not connected");
|
||||
while(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void buzzOff()
|
||||
{
|
||||
noTone(BUZZER_PIN);
|
||||
pinMode(BUZZER_PIN, INPUT);
|
||||
}
|
||||
|
||||
void helloBuzz() {
|
||||
tone(BUZZER_PIN, 500, 100);
|
||||
delay(100);
|
||||
tone(BUZZER_PIN, 1000, 100);
|
||||
delay(100);
|
||||
tone(BUZZER_PIN, 4000, 100);
|
||||
delay(100);
|
||||
buzzOff();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
tone(BUZZER_PIN, 100, 5);
|
||||
tick();
|
||||
|
||||
// scanner.Scan();
|
||||
|
||||
lcd.print(" cewk-o-mator ");
|
||||
lcd.print(" HSWAW 2024 ");
|
||||
|
||||
PCF.write8(0b11110000); // first 4 bits are columns, low when pressed
|
||||
// PCF.write8(0b00001111); // last 4 bits are rows, low when pressed
|
||||
int x = PCF.read8();
|
||||
// Serial.print("Keyboard: ");
|
||||
// Serial.println(x, BIN);
|
||||
|
||||
bool clk = digitalRead(CLK_PIN);
|
||||
bool dt = digitalRead(DT_PIN);
|
||||
bool sw = digitalRead(SW_PIN);
|
||||
|
||||
Serial.print("CLK: ");
|
||||
Serial.print(clk);
|
||||
Serial.print(" DT: ");
|
||||
Serial.print(dt);
|
||||
Serial.print(" SW: ");
|
||||
Serial.println(sw);
|
||||
debugScanI2C();
|
||||
demoScreen();
|
||||
// demoKeyboard();
|
||||
// demoEncoder();
|
||||
|
||||
delay(200);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#include "constants.h"
|
||||
#include <LCD_I2C.h>
|
||||
#include <Wire.h>
|
||||
|
||||
LCD_I2C lcd(LCD_I2C_ADDR, LCD_COLS, LCD_ROWS);
|
||||
|
||||
bool setupScreen() {
|
||||
lcd.begin();
|
||||
|
||||
Wire.beginTransmission(LCD_I2C_ADDR);
|
||||
if (Wire.endTransmission() != 0) {
|
||||
Serial.println("LCD not connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
lcd.backlight();
|
||||
lcd.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void demoScreen() {
|
||||
lcd.print(" cewk-o-mator ");
|
||||
lcd.print(" HSWAW 2024 ");
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
bool setupScreen();
|
||||
void demoScreen();
|
Loading…
Reference in New Issue