#include <SPI.h>
#include <Wire.h> // Include Wire library (required for I2C devices)
#include <Adafruit_GFX.h> // Include Adafruit graphics library
#include <Adafruit_SSD1306.h> // Include Adafruit SSD1306 OLED driver
#include <EEPROM.h> // Include EEPROM
#define PWM 14
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
//#define OLED_RESET 5
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define button2 6 // Button B2 is connected to Arduino pin 8
#define button4 7 // Button B4 is connected to Arduino pin 7
int valorPWM;
void setup()
{
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr
// Clear the display buffer.
display.clearDisplay();
//display.display();
display.setTextColor(WHITE, BLACK);
pinMode(button2, INPUT);
pinMode(button4, INPUT);
//display.clearDisplay();
display.setCursor(0, 0);
display.setTextSize(1);
display.print("HOLA");
display.display();
}
void loop()
{
int lectura_boton2 = digitalRead(button2);
if (lectura_boton2 == 0)
{
valorPWM++;
analogWrite(PWM, valorPWM);
Serial.println(valorPWM);
display.setCursor(0, 0);
display.setTextSize(1);
display.print("Valor PWM:");
display.setCursor(60, 0);
display.setTextSize(1);
display.print(valorPWM);
display.display();
delay(300);
}
int lectura_boton4 = digitalRead(button4);
if (lectura_boton4 == 0)
{
display.clearDisplay();
valorPWM--;
analogWrite(PWM, valorPWM);
Serial.println(valorPWM);
display.setCursor(0, 0);
display.setTextSize(1);
display.print("Valor PWM:");
display.setCursor(60, 0);
display.setTextSize(1);
display.print(valorPWM);
display.display();
delay(300);
}
}