ciao a tutti, io vorrei usare un display oled e contemporaneamente far andare una parte di programma che funzioni tipo da menu, cioè vorrei interagire con il display ma ho dei problemi con i void.
ho provato a far accendere un led mentre visualizzavo delle grafiche sul display ma niente
#define LED 12 // LED collegato al pin digitale 13
#define BUTTON 7 // pin di input dove è collegato il pulsante
int but = 0;
#include "U8glib.h"
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC
void setup(void) {
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
}
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 80, 14, "PAN");
u8g.drawStr( 80, 46, "TILT");
// u8g.drawFrame(0,0,64,64);
u8g.drawFrame(70,0,58,32);
u8g.drawFrame(70,32,58,32);
u8g.drawPixel(32,0);
u8g.drawPixel(32,8);
u8g.drawPixel(32,16);
u8g.drawPixel(32,24);
u8g.drawPixel(32,32);
u8g.drawPixel(32,40);
u8g.drawPixel(32,48);
u8g.drawPixel(32,56);
u8g.drawPixel(32,63);
u8g.drawPixel(32,70);
u8g.drawPixel(0,32);
u8g.drawPixel(8,32);
u8g.drawPixel(16,32);
u8g.drawPixel(24,32);
u8g.drawPixel(32,32);
u8g.drawPixel(40,32);
u8g.drawPixel(48,32);
u8g.drawPixel(56,32);
u8g.drawPixel(63,32);
u8g.drawPixel(70,32);
int oriz = analogRead(A0) / 16;
int vert = analogRead(A1) / 16;
int ORIZ = map(oriz, 0, 64, -100, +100);
int VERT = map(vert, 0, 64, -100, +100);
u8g.drawDisc(oriz, vert, 3);
char buf[9];
sprintf (buf, "%d", ORIZ);
u8g.drawStr(80, 28, buf );
char fub[9];
sprintf (fub, "%d", VERT );
u8g.drawStr(80, 60, fub );
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
but=digitalRead(BUTTON);
if(but==HIGH) {
digitalWrite(LED,HIGH);
var1=1;
}
if(but==HIGH) {
digitalWrite(LED,LOW);
var1=0;
}
}