I have been using the 4 wire LCD display with shield from banggood
and using the i2c driver from
http://robojax.com/learn/arduino/?vid=robojax-LCD1602-I2C
It was working perfectly on the web create.arduino.cc in December 2019
Now (February 2020) the exact same code, exact same library no longer works on create.arduino.cc
But it works perfectly using the locally installed arduino.
Something appears to have been broken on the website.
Anyone else found this?
Here is the code that works perfectly on my desktop version of Arduino but not longer works on the create.arduino.cc (it used to work perfectly on create.arduino.cc).
It crashes on the line lcd.begin(); and I have no idea why.
Can anyone help me with this?
// stop it game
// single player LED Game
// January 2020
// Use this one for my students in 8MT
// thanks to
// https://www.instructables.com/id/StopIt-LED-Game-powered-by-arduino/
// Setup the LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2); // 16 characters, 2 rows
// initialise the LEDs and Button
int Led1Pin = 2; //The pin of the first LED.
int Led2Pin = 3; //The pin of the second LED.
int Led3Pin = 4; //etc.
int Led4Pin = 5;
int Led5Pin = 6;
int Buzzer = 7; // The pin of the buzzer
int ButtonPin = 8; //The pin of the button.
//The state of the button
boolean old_val = LOW;
boolean buttonPress = LOW;
// Flag button press so we can only press one time per light
int buttonFlag = 0;
// My current score
int score = 0;
// High score
int HighScore = 0;
//Stores which LED is on.
int LightPosition = 0;
//How much time in between LED light changes.
int pause = 1000;
//What time it was when we last moved the light.
long lastMove = millis();
// ----------------------------------------------------
void setup()
{
pinMode(Led1Pin, OUTPUT);
pinMode(Led2Pin, OUTPUT);
pinMode(Led3Pin, OUTPUT);
pinMode(Led4Pin, OUTPUT);
pinMode(Led5Pin, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(ButtonPin, INPUT);
// Robojax code for LCD with I2C
// initialize the LCD
lcd.begin(); // lcd is an object, begin is a method
Serial.begin(9600); // initialise serial monitor
// Turn on the blacklight and print a message.
lcd.backlight(); // turn on the backlight
lcd.print("Jesus is Lord!");
//Start a new game.
newGame();
// ----------------------------------------
}
void loop()
{
// Read the button input
buttonPress = digitalRead(ButtonPin);
//Current time
long currTime = millis();
//Move the light.
if(currTime - lastMove >= pause)
{
lastMove = currTime; //Remember when we switched LED
LightPosition++; //increment the Light position.
if(LightPosition >= 6) LightPosition = 1;
move(LightPosition);//Update the light position.
// Set button flag back to 0 for next round
buttonFlag = 0;
}
//When the player presses the button...
if(buttonPress == HIGH && old_val == LOW && buttonFlag == 0)
{
//If the pressed it when the light was in the middle, speed up and continue.
if(LightPosition == 3)
{
// We win, increase the score
score++;
if (score > HighScore) HighScore = score;
// Flag the button press to stop double press/win
buttonFlag = 1;
digitalWrite(Led3Pin, LOW);
delay(50);
digitalWrite(Led3Pin, HIGH);
//Speed up the game.
if (pause > 700) {
pause -= 100;
} else if (pause > 500) {
pause -= 50;
} else if (pause > 300) {
pause -= 20;
} else if (pause > 10) {
pause -= 10;
} else if (pause > 1) {
pause -= 1;
}
updateLCD();
String outputScore = "Score: " + String(score);
String outputDelay = "Delay: " + String(pause);
Serial.println(outputScore);
Serial.println(outputDelay);
} else //If the pressed it at the wrong time, show their final score and start a new game.
{
//Game over
Serial.println("GAME OVER");
Serial.println("Final Score ");
Serial.println(score);
lcd.clear();
lcd.print("Game Over :(");
lcd.setCursor (0,1); // go to the start of 2nd line
lcd.print("Score:" + String(score) + " High:" + String(HighScore));
//Blink the Led that the player stopped on.
for (int x = 0; x <= 10; x++)
{
if(digitalRead(LightPosition + 1) == LOW)
{
digitalWrite(LightPosition + 1, HIGH);
tone(Buzzer, 1000);
}
else
{
digitalWrite(LightPosition + 1, LOW);
noTone(Buzzer);
}
delay(200);
}
//Show a LED bar based on how well the player did.
digitalWrite(Led1Pin,HIGH);
delay(500);
if (pause < 800)
{
digitalWrite(Led2Pin, HIGH);
delay(500);
}
if (pause < 600)
{
digitalWrite(Led3Pin, HIGH);
delay(500);
}
if (pause < 250)
{
digitalWrite(Led4Pin, HIGH);
delay(500);
}
if (pause < 100)
{
digitalWrite(Led5Pin, HIGH);
delay(500);
}
delay(3000);
newGame();
}
}
old_val = buttonPress;
}
//Updates the light's position.
void move(int LightPosition)
{
//Turn off all LEDs
for (int x = Led1Pin; x <= Led5Pin;x++)
{
digitalWrite(x, LOW);
}
//Turn on the LED
digitalWrite(LightPosition + 1, HIGH);
}
void newGame()
{
LightPosition = 0;
pause = 1000;
score = 0;
Serial.println("New Game: Score 0");
updateLCD();
}
void updateLCD()
{
// LCD setup for new game
lcd.clear();
lcd.print("Score:" + String(score) + " High:" + String(HighScore));
lcd.setCursor (0,1); // go to the start of 2nd line
lcd.print("Delay:" + String(pause));
}