Hola! Como estan? Estoy haciendo un proyecto de una máquina expendedora y me está costando bastante.
Comencé por probar ejemplos simples para luego juntarlos y obtener mi programación, por ejemplo, en este caso quiero hacer que mediante un pulsador una pantalla oled se encienda y se apague.
Realicé un ejemplo de pulsador y led con true-false y otro de pantalla oled.
Intenté unirlos como creo que es correcto pero tengo este error que no logro entender.
Para aclarar porque ya me lo han preguntado, el -1 de la pantalla oled me apareción en el ejemplo como denominador de los dos pines que usa la pantalla SCL y SDA. Si existe otra forma también agradecería que me dijeran.
Muchas gracias.
const int buttonPin = 12;
const int oledPin = -1;
int buttonState = 0;
boolean OLED_ON;
boolean FLAG_PULSE;
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
pinMode(oledPin, OUTPUT);
pinMode(buttonPin, INPUT);
OLED_ON = false;
FLAG_PULSE = true;
}
if display.begin(SSD1306_SWITCHCAPVCC, 0x3C) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
}
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 10);
// Display static text
display.println("SU PAGO FUE REALIZADO CORRECTAMENTE");
display.display();
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && OLED_ON == false && FLAG_PULSE == true) {
digitalWrite(oledPin, HIGH);
OLED_ON = true; FLAG_PULSE = false;
}
else if (buttonState == HIGH && LED_ON == true && FLAG_PULSE == true) {
digitalWrite(oledPin, LOW);
OLED_ON = false;
FLAG_PULSE = false;
}
else if (buttonState == LOW && FLAG_PULSE == false) {
FLAG_PULSE = true;
}
}
}
Hola! Tengo un problema con mi programación, específicamente en la línea de void loop.
Si alguien me puede explicar, probé con borrar algunas { o colocarlas en otras maneras pero no consigo resolver el problema.
Gracias!
const int buttonPin = 12;
const int oledPin = -1;
int buttonState = 0;
boolean OLED_ON;
boolean FLAG_PULSE;
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
pinMode(oledPin, OUTPUT);
pinMode(buttonPin, INPUT);
OLED_ON = false;
FLAG_PULSE = true;
if (display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 10);
// Display static text
display.println("SU PAGO FUE REALIZADO CORRECTAMENTE");
display.display();
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && OLED_ON == false && FLAG_PULSE == true) {
digitalWrite(oledPin, HIGH);
OLED_ON = true; FLAG_PULSE = false;
}
else if (buttonState == HIGH && OLED_ON == true && FLAG_PULSE == true) {
digitalWrite(oledPin, LOW);
OLED_ON = false;
FLAG_PULSE = false;
}
else if (buttonState == LOW && FLAG_PULSE == false){
FLAG_PULSE = true;
}
}
Ya tienes otro tema con un problema similar, ojo que es doble posteo.
Por otro lado tu problema no se resuelve moviendo, quitando o agregando llaves.
Se resuelve entendiendo lo que se hace.
Ten presente que el lenguaje de arduino tiene una sintaxis que se debe respetar.
Moderador:
Por favor, lee las Normas del foro y espero que este sea tu primer y ultimo doble posteo. Quedas anotado con 1 primer advertencia por doble posteo, a la segunda sanción de 1 dia sin poder ingresar al foro y luego crece en potencia de 2.
Respuestas a este post por privado.
Quedas advertido!!