Académique Documents
Professionnel Documents
Culture Documents
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//LCD configuration
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C
lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKL
IGHT_PIN,POSITIVE);
void setup()
{
//Prepare screen
lcd.begin(20,4);
lcd.home ();
lcd.setCursor(4,0);
lcd.print("Trans Status");
lcd.setCursor(0,2);
lcd.print("Current Gear:");
lcd.setCursor(0,3);
lcd.print("Lockup clutch:");
//Initialize serial
Serial.begin(9600);
//Initialize relays in OFF position
digitalWrite(solenoid1, HIGH);
digitalWrite(solenoid2, HIGH);
digitalWrite(LUsolenoid, HIGH);
//Set pins to output mode
pinMode(solenoid1, OUTPUT);
pinMode(solenoid2, OUTPUT);
pinMode(LUsolenoid, OUTPUT);
//Pins for switches
pinMode(masterSwitch, INPUT_PULLUP);
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
//Pins for gear sensing
pinMode(S1read, INPUT);
pinMode(S2read, INPUT);
pinMode(LUread, INPUT);
}
void loop()
{
//Serial counter to watch loop times
Serial.println(counter);
//Master switch goes between auto and manual
if (digitalRead(masterSwitch) == 1) {
active = 1;
}
else{
active = 0;
}
}
void lockupDisengage(int noDelay)
{
digitalWrite(LUsolenoid, HIGH);
lockupStatus = 0;
//Delay before continuing in case of pending gear change
if (noDelay != 1) {
delay(750);
}
}
//upShift and downShift are called by the shifter buttons for
sequential gearchanges.
//Handles TC lockup, prevents shifting above 4th or below 1st
void upShift()
{
if (currentGear == 4) {
lockupEngage(0);
}
if (currentGear < 4) {
currentGear++;
if (lockupStatus == 1) {
lockupDisengage(0);
}
}
switch (currentGear) {
{
case 2:
secondGear();
}
break;
{
case 3:
thirdGear();
}
break;
{
case 4:
fourthGear();
}
break;
}
}
void downShift()
{
if ((currentGear == 4) && (lockupStatus == 1)) {
lockupDisengage(0);
}
else {
if (currentGear > 1) {
currentGear--;
if (lockupStatus == 1) {
lockupDisengage(0);
}
}
switch (currentGear) {
{
case 1:
firstGear();
}
break;
{
case 2:
secondGear();
}
break;
{
case 3:
thirdGear();
}
break;
}
}
}