Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruemelbahn authored Dec 5, 2023
0 parents commit 26ebfb9
Show file tree
Hide file tree
Showing 7 changed files with 875 additions and 0 deletions.
Binary file added I2C-LCD-Anzeige.pdf
Binary file not shown.
85 changes: 85 additions & 0 deletions LCDPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/***************************************************
* LCDPanel.cpp v1.0 - LCD/I2C communication for Arduino
*
* Copyright (c) 2018 Michael Zimmermann <http://www.kruemelsoft.privat.t-online.de>
* All rights reserved.
*
* Derived class from Adafruit_RGBLCDShield
* Original source (Adafruit_RGBLCDShield) written by Limor Fried/Ladyada for Adafruit Industries
* <http://http://www.adafruit.com/products/714>
*
* LICENSE
* -------
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
****************************************************/

#include "LCDPanel.h"

#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <Wire.h>

#ifdef __AVR__
#define WIRE Wire
#else // Arduino Due
#define WIRE Wire1
#endif

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

uint8_t LCDPanel::detect_i2c(uint8_t ui8_LcdAddr)
{
Wire.begin();
Wire.beginTransmission(ui8_LcdAddr);
return Wire.endTransmission();
}

void LCDPanel::begin(uint8_t cols, uint8_t rows, uint8_t charsize)
{
// init of MCP28017 before initializing from Adafruit_RGBLCDShield:
i2c.begin();
Adafruit_RGBLCDShield::begin(cols, rows, charsize);
i2c.pinMode(BUTTON_BACKLIGHT, INPUT);
i2c.pullUp(BUTTON_BACKLIGHT, HIGH);

// After setting up the button, setup the Bounce instances :
debouncer_Left.attach (i2c, 4, DEBOUNCE_TIME);
debouncer_Up.attach (i2c, 3, DEBOUNCE_TIME);
debouncer_Down.attach (i2c, 2, DEBOUNCE_TIME);
debouncer_Right.attach(i2c, 1, DEBOUNCE_TIME);
debouncer_OK.attach (i2c, 0, DEBOUNCE_TIME);
}

void LCDPanel::updateDebounce()
{
// Update the Bounce instances :
debouncer_Left.update();
debouncer_Up.update();
debouncer_Down.update();
debouncer_Right.update();
debouncer_OK.update();
}

uint8_t LCDPanel::readButtonA5(void)
{
uint8_t reply(BUTTON_A5);
reply &= ~((i2c.digitalRead(BUTTON_BACKLIGHT)) << 5);
return reply;
}
71 changes: 71 additions & 0 deletions LCDPanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/***************************************************
* LCDPanel.h v1.0 - LCD/I2C communication for Arduino
*
* Copyright (c) 2018 Michael Zimmermann <http://www.kruemelsoft.privat.t-online.de>
* All rights reserved.
*
* Derived class from Adafruit_RGBLCDShield
* Original source (Adafruit_RGBLCDShield) written by Limor Fried/Ladyada for Adafruit Industries
* <http://http://www.adafruit.com/products/714>
*
* LICENSE
* -------
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
****************************************************/

#ifndef _KS_LCDPanel_h
#define _KS_LCDPanel_h

#include <inttypes.h>
#include "Adafruit_RGBLCDShield.h"
#include "Bounce2mcp.h"

#define BUTTON_FCT_BACK (BUTTON_LEFT | BUTTON_UP | BUTTON_DOWN)
#define BUTTON_A5 0x20

#define BUTTON_BACKLIGHT 5
#define LCD_BACKLIGHT 6

#define DEBOUNCE_TIME 5

class LCDPanel : public Adafruit_RGBLCDShield {
public:
LCDPanel() {};
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);

Adafruit_MCP23017* getMCP() { return &i2c; }

uint8_t detect_i2c(uint8_t ui8_LcdAddr);

uint8_t readButtonA5();

void updateDebounce();

// Instantiate the Bounce objects
BounceMcp debouncer_Left;
BounceMcp debouncer_Right;
BounceMcp debouncer_Up;
BounceMcp debouncer_Down;
BounceMcp debouncer_OK;

protected:
Adafruit_MCP23017 i2c;

private:
// just a comment for variable used in Adafruit_RGBLCDShield:
// uint8_t _i2cAddr; ==> 0 = i2c is used; 255 = wired connection instead use of i2c
};

#endif
Loading

0 comments on commit 26ebfb9

Please sign in to comment.