Good evening everyone. I am working on one of my first projects and I need to switch high voltage. I was recommended to use the 4x4 Driver Shield from some guys on another forum. SInce I am new, I am having a hell of a time trying to understand how to use it and the manual doesnt give much help. All I am trying to simply do is take my existing code and instead of outputing LedPin1 and LedPin2 HIGH or LOW; output to pin 3 and 4 on the DB-25 connector.
Any help is much appreciated. My code is below.
#include "ST7565.h"
// pin 6 - Serial data out (SID)
// pin 5 - Serial clock out (SCLK)
// pin 4 - Data/Command select (RS or A0)
// pin 3 - LCD reset (RST)
// pin 2 - LCD chip select (CS)
ST7565 glcd(6, 5, 4, 3, 2);
/******************************************/
const int buttonPinUp = A2; // the number of the pushbutton pin
const int buttonPinDown = A1; // the number of the pushbutton pin
const int buttonPinMode = A0; // the number of the pushbutton pin
const int ledPin1 = A3; // the number of the LED pin
const int ledPin2 = A4; // the number of the LED pin
const int ledPinTCC = A5; // the number of the LED pin
/******************************************/
int gear = 1;
boolean autoshift = true;
//boolean locktcc = false;
// Variables will change:
int ledState = HIGH; // the current state of the output pin
int buttonStateUp; // the current reading from the input pin
int lastButtonStateUp = LOW; // the previous reading from the input pin
int buttonStateDown; // the current reading from the input pin
int lastButtonStateDown = LOW; // the previous reading from the input pin
int buttonStateMode; // the current reading from the input pin
int lastButtonStateMode = LOW; // the previous reading from the input pin
long lastDebounceTimeUp = 0; // the last time the output pin was toggled
long lastDebounceTimeDown = 0; // the last time the output pin was toggled
long lastDebounceTimeMode = 0; // the last time the output pin was toggled
long debounceDelay = 20; // the debounce time; increase if the output flickers
/***********************************************/
// The setup() method runs once, when the sketch starts
void setup() {
pinMode(buttonPinUp, INPUT);
pinMode(buttonPinDown, INPUT);
pinMode(buttonPinMode, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// set initial LED state
//digitalWrite(ledPin1, LOW);
Serial.begin(9600);
Serial.print(freeRam());
// initialize and set the contrast to 0x18
glcd.begin(0x18);
glcd.display(); // show splashscreen
delay(2500);
glcd.clear();
// draw a string at location (0,0)
glcd.clear();
glcd.display();
glcd.drawstring(0, 0, "FST_Shift v0.01");
glcd.display();
delay(1000);
glcd.clear();
glcd.display();
}
// this handy function will return the number of bytes currently free in RAM, great for debugging!
int freeRam(void)
{
extern int __bss_end;
extern int *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) - ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) - ((int)__brkval);
}
return free_memory;
}
void loop() {
// read the state of the switch into a local variable:
int readingUp = digitalRead(buttonPinUp);
int readingDown = digitalRead(buttonPinDown);
int readingMode = digitalRead(buttonPinMode);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (readingUp != lastButtonStateUp) {
// reset the debouncing timer
lastDebounceTimeUp = millis();
}
if (readingDown != lastButtonStateDown) {
// reset the debouncing timer
lastDebounceTimeDown = millis();
}
if (readingMode != lastButtonStateMode) {
// reset the debouncing timer
lastDebounceTimeMode = millis();
}
if ((millis() - lastDebounceTimeUp) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (readingUp != buttonStateUp) {
buttonStateUp = readingUp;
// only toggle the LED if the new button state is HIGH
if (buttonStateUp == HIGH) {
ledState = !ledState;
gear++;
if (gear > 4) gear = 4;
Serial.write("UP\n");
}
}
}
if ((millis() - lastDebounceTimeDown) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (readingDown != buttonStateDown) {
buttonStateDown = readingDown;
// only toggle the LED if the new button state is HIGH
if (buttonStateDown == HIGH) {
//ledState = !ledState;
gear--;
if (gear < 1) gear = 1;
Serial.write("DOWN\n");
}
}
}
if ((millis() - lastDebounceTimeMode) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (readingMode != buttonStateMode) {
buttonStateMode = readingMode;
// only toggle the LED if the new button state is HIGH
if (buttonStateMode == HIGH) {
autoshift = !autoshift;
Serial.write("MODE\n");
}
}
}
switch (gear) {
case 1:
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
//analogWrite(ledPin1, HIGH);
//analogWrite(ledPin2, LOW);
break;
case 2:
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
break;
case 3:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
break;
case 4:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
break;
};
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonStateUp = readingUp;
lastButtonStateDown = readingDown;
lastButtonStateMode = readingMode;
/*
*/
char stgear[6];
String stmode;
char stmodee[10];
if (autoshift==true) {
stmode = "AUTO";
} else {
stmode = "MANUAL";
}
stmode.toCharArray(stmodee, 10);
itoa(gear, stgear, 10);
glcd.clear();
glcd.drawstring(0, 0, stgear);
glcd.drawstring(0, 1, stmodee);
glcd.display();
}