Hi all
I'm in the process of trying to build a controller for a camera slider which is pwered by an Uno + linksprite motor shield and a dc motor. I have the thing running fine but i am trying to add an LCD and several preset options to allow my more felxibility when out and about. The motor sketch works well when set up alone with just the shield and uno. When I link the lcd in and upload the unfinished but should work sketch, there are a fwe LED's not lighting up on the motor shield which should be, so i think i am not getting power to it properly. They are connected as follows:
Top to bottom:
Motor shield - protoshield - uno - LCD is connected detached via 5v, GND and SCL/SDA.
The lcd works fine and the button presses register as they should. Now, the LED's on the motor shield (when correctly working) are lit up as follows: Green V_LOGIC LED, Red IN1 (Digital Pin 8) and green IN4 (Digital Pin 13) When this is all connected with the lcd and the below sketch is uploaded,. the LCD still works but the only LED on the motor shield that is lit up is the V_LOGIC.
Can someone maybe give any ideas on resolving this?
// Libraries for the Adafruit RGB/LCD Shield
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
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
#define BUTTON_SHIFT BUTTON_SELECT
// Motor shield
//
//
int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface
int pinI4=13;//define I4 interface
int speedpinB=10;//enable motor B
int rpm =250;//define the speed of motor
// ************************************************
// Setup and diSplay initial screen
// ************************************************
void setup()
{
Serial.begin(9600);
// Initialize LCD DiSplay
lcd.begin(16, 2);
lcd.setBacklight(WHITE);
lcd.print(("ISO 100"));
lcd.setCursor(0, 1);
lcd.print(("TIMELAPSE"));
uint8_t i=0;
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
}
void Splash()
{
analogWrite(speedpinA,rpm);//input a simulation value to set the speed
analogWrite(speedpinB,rpm);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
digitalWrite(pinI1,HIGH);
}
void stopSplash()
{
digitalWrite(speedpinA,LOW);// Unenable the pin, to stop the motor. this should be done to avoid damaging the motor.
digitalWrite(speedpinB,LOW);
delay(0); // pause time of camera moving in milliseconds
}
void loopSplash()
{
Splash();
delay(0); // time motor spins for in milliseconds
stop();
}
void Preset_1()//Main function
{
analogWrite(speedpinA,rpm);//input a simulation value to set the speed
analogWrite(speedpinB,rpm);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
digitalWrite(pinI1,HIGH);
}
void stop()
{
digitalWrite(speedpinA,LOW);// Unenable the pin, to stop the motor. this should be done to avoid damaging the motor.
digitalWrite(speedpinB,LOW);
delay(5000); // pause time of camera moving in milliseconds
}
void preset_1()//Final loop
{
Preset_1();
delay(175); // time motor spins for in milliseconds
stop();
}
void Preset_2()
{
}
void Preset_3()
{
}
void Preset_4()
{
}
// ************************************************
// States for state machine
// ************************************************
enum operatingState {SPLASH = 0, PRESET_1, PRESET_2, PRESET_3, PRESET_4};
operatingState opState = SPLASH;
// ************************************************
// Main Control Loop
//
// All state changes pass through here
// ************************************************
void loop()
{
uint8_t buttons = lcd.readButtons();
if (buttons) {
lcd.clear();
lcd.setCursor(0,0);
if (buttons & BUTTON_UP) {
lcd.print("PRESET 1 ");
lcd.setBacklight(WHITE);
}
if (buttons & BUTTON_RIGHT) {
lcd.print("PRESET 2 ");
lcd.setBacklight(WHITE);
}
if (buttons & BUTTON_DOWN) {
lcd.print("PRESET 3 ");
lcd.setBacklight(WHITE);
}
if (buttons & BUTTON_LEFT) {
lcd.print("PRESET 4 ");
lcd.setBacklight(WHITE);
}
if (buttons & BUTTON_SELECT) {
lcd.print("PRESET SELECTED! ");
lcd.setBacklight(WHITE);
switch (opState)
{
case SPLASH:
void Splash();
break;
case PRESET_1:
void Preset_1();
break;
case PRESET_2:
void Preset_2();
break;
case PRESET_3:
void Preset_3();
break;
case PRESET_4:
void Preset_4 ();
break;
}
}
}
}