I am trying to add an OLED display to my robot to display the readout from the serial monitor. When I try to compile it it gives me an error "Error compiling for board Arduino Uno". I don't know if this is even close to correct. My problem is, when I have it connected to my computer the robot does what I want it to. When I use the 9v battery pack that is on the robot it acts different. I put fresh batteries in and still have the issue of not functioning like it's programmed. My idea was to add an OLED so I could see if the photoresistor is reading the same on the battery as it is on the computer power. If it's different I will adjust the program to function with the readings while it's on the battery power. Thanks in advance for any help.
#include <Servo.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo_bmp[]={B00000000, B11000000,
B00000001, B11000000, B00000001, B11000000, B00000011, B11100000, B11110011,
B11100000, B11111110, B11111000, B01111110, B11111111, B00110011, B10011111,
B00011111, B11111100, B00001101, B01110000, B00011011, B10100000, B00111111,
B11100000, B00111111, B11110000, B01111100, B11110000, B01110000, B01110000,
B00000000, B00110000 };
#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
Servo myservo1;
Servo myservo2;
int white=800;
int black=500;
#include <RGBLed.h>
RGBLed led(5, 6, 7, RGBLed::COMMON_CATHODE);
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) // init done // Show image buffer on the display hardware.
display.display(); //delay(2000);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 0);
display.clearDisplay();
display.println("INPUT YOUR TEXT HERE: ");
// invert the display
display.invertDisplay(true);
display.invertDisplay(false);
display.display();
display.clearDisplay();
led.setColor(255, 255, 255);
myservo1.attach(12);
myservo2.attach(13);
int val = analogRead(2);
Serial.println("white = "); Serial.print(white);
Serial.print("black="); Serial.print(black);
Serial.print("val="); Serial.print(val);
if(val>white) {slow_left(); }
else if (val<black) {slow_right(); }
else {slow_forward();}
}
void slow_forward()
{
myservo1.writeMicroseconds(1400);
myservo2.writeMicroseconds(1530);
}
void slow_right()
{
myservo1.writeMicroseconds(1410);
myservo2.writeMicroseconds(1600);
}
void slow_left()
{
myservo1.writeMicroseconds(1275);
myservo2.writeMicroseconds(1500);
}
void loop() {
while (1) {
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 0);
display.clearDisplay();
display.println("input:");
printText();
display.display();
}
}
void printText(void){
String s;
if(Serial.available()){
s=Serial.readString(); //getting string input in variable "s"
display.println(s);
display.display();
display.println("\n");
}
delay(1000);
}
