Moderators: adafruit_support_bill, adafruit
/*********************
Example code for the Adafruit RGB Character LCD Shield and Library
This code displays text on the shield, and also reads the buttons on the keypad.
When a button is pressed, the backlight changes color.
**********************/
// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
void setup() {
// Debugging output
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD. We track how long it takes since
// this library has been optimized a bit and we're proud of it :)
int time = millis();
lcd.print("Hello, world!");
time = millis() - time;
Serial.print("Took "); Serial.print(time); Serial.println(" ms");
lcd.setBacklight(ON);
}
uint8_t i=0;
void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}Bigjeep093 wrote:I moved the ground pin over one pin and it works perfectly now.
___________________
int relay2 = 2; // set relay 2 at pin 2
pinMode(relay2, OUTPUT); // set relay2 on pin 2 as output
if (BUTTON_UP == HIGH)
{
if (relay2 == LOW);
digitalWrite(relay2, HIGH);
}
else
digitalWrite(relay2, LOW);
}
if (relay2 == LOW);
digitalWrite(relay2, HIGH);
if (digitalRead(BUTTON_UP) == HIGH)
{
if (digitalRead(relay2) == LOW);
digitalWrite(relay2, HIGH);
}
else
digitalWrite(relay2, LOW);
}
digitalWrite(relay2, digitalRead(BUTTON_UP));
// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
#include <OneWire.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
uint8_t i=0;
void loop()
{
uint8_t buttons = lcd.readButtons();
if (buttons)
{
if (buttons & BUTTON_UP) // Button UP is TEMP UP
{
lcd.print("UP ");
}
if (buttons & BUTTON_DOWN) // Button DOWN is TEMP DOWN
{
lcd.print("DOWN ");
}
if (buttons & BUTTON_LEFT) // Button LEFT is PUMP 1, relay 2
{
if (relay2 == LOW);
digitalWrite(relay2, HIGH);
}
else
digitalWrite(relay2, LOW);
}
if (buttons & BUTTON_RIGHT) // Button RIGHT is PUMP 2, relay 3
{
if (relay3 == LOW);
digitalWrite(relay3, HIGH);
}
else
digitalWrite(relay3, LOW);
if (buttons & BUTTON_SELECT) // Button SECLECTis LIGHT, relay 4
{
if (relay4 == LOW);
digitalWrite(relay4, HIGH);
}
else
digitalWrite(relay4, LOW);
}
Bigjeep093 wrote:I didn't declare the buttons, they are from the RGB LCD shield example HELLO WORLD.
if (buttons & BUTTON_LEFT) // Button LEFT is PUMP 1, relay 2
{
if (digitalRead(relay2) == LOW) //; no semicolon!
digitalWrite(relay2, HIGH);
}
else
digitalWrite(relay2, LOW);
// } doesn't pair with anything
if (buttons & BUTTON_RIGHT) // Button RIGHT is PUMP 2, relay 3
{
if (digitalRead(relay3) == LOW) //; no semicolon!
digitalWrite(relay3, HIGH);
}
else
digitalWrite(relay3, LOW);
if (buttons & BUTTON_SELECT) // Button SECLECTis LIGHT, relay 4
{
if (digitalRead(relay4) == LOW) //; no semicolon!
digitalWrite(relay4, HIGH);
}
else
digitalWrite(relay4, LOW);
}
if (buttons & BUTTON_LEFT) // Button LEFT is PUMP 1, relay 2
digitalWrite(relay2, HIGH);
else
digitalWrite(relay2, LOW);
if (buttons & BUTTON_RIGHT) // Button RIGHT is PUMP 2, relay 3
digitalWrite(relay3, HIGH);
else
digitalWrite(relay3, LOW);
if (buttons & BUTTON_SELECT) // Button SECLECTis LIGHT, relay 4
digitalWrite(relay4, HIGH);
else
digitalWrite(relay4, LOW);
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
if (digitalRead(buttonPin) == HIGH) // button is pressed
{
if (digitalRead(ledPin) == LOW) // see if the LED is on or off, if it is HIGH skip to else
digitalWrite(ledPin, HIGH); // if it is LOW turn to HIGH
}
else // if above is not true then do this
{
digitalWrite(ledPin, LOW); // turn LED to LOW
}
}
Return to Arduino Shields from Adafruit
Users browsing this forum: Bymbomietty and 6 guests