#include <TinyDebug.h>
#include <TinyWireM.h>
#include <TinyLiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>
#include "MyButton.h"
#include "MyEncoder.h"
#define GPIO_ADDR 0x3F // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A
const byte encDtPin {PB3} ;
const byte encClkPin {PB4} ;
const byte encSwPin {PB5} ;
const byte wsDtPin {PB1};
const byte nbPixels {12};
const byte i2cSclPin {PB2};
const byte i2cSdaPin {PB0};
Adafruit_NeoPixel pixels(nbPixels, wsDtPin, NEO_GRB + NEO_KHZ800);
TinyLiquidCrystal_I2C lcd(GPIO_ADDR, 20, 4); // set address & 16 chars / 2 lines
MyEncoder encoder(encClkPin, encDtPin);
MyButton button(encSwPin);
void pixelShow(int value)
{
int numPxl ( value % nbPixels );
if (numPxl < 0)
{
numPxl += nbPixels;
}
for (int pxl=0; pxl < nbPixels; pxl++)
{
if ( numPxl == pxl)
{
pixels.setPixelColor(pxl, pixels.Color(0, 0, 255));
}
else
{
pixels.setPixelColor(pxl, pixels.Color(255, 0, 0));
}
pixels.show();
}
}
void setup()
{
// Initialize Debugger
Debug.begin();
// Initialize encoder pins
encoder.begin();
button.begin();
// Initialize pixelRing pins
pixels.begin();
// Initialize display pins
lcd.begin(4, 20);
}
void loop()
{
// Lire l'encodeur
MyEncoder::EncStatus encStatus = encoder.read();
if ( encStatus != MyEncoder::EncNOCHG)
{
Debug.print(F("Valeur encodeur = "));
Debug.println(encoder.counter());
pixelShow(encoder.counter());
}
// Lire l'interrupteur
if (button.read())
{
switch (button.status())
{ case MyButton::ButtonUP :
Debug.print(F("Sens bouton = "));
Debug.println(F("UP"));
break;
case MyButton::ButtonDOWN :
Debug.print(F("Sens bouton = "));
Debug.println(F("DOWN"));
}
}
}