Hi Guys, I am struggling with the format of the command to get the following working:
I have a keypad, and a TFT, the system should wait for input, and if it equals a certain number, move a stepper motor to a pre-defined degree.My problem is that I somehow cannot figure the command out, or rather the format of the command.
I have defined the following:
// Variable
String confkey;
int num;
void loop()
{
IRAval1 = digitalRead(IRSensor1);
IRAval2 = digitalRead(IRSensor2);
if ((IRAval1<=0)&&(IRAval2=0))
{digitalWrite(BY_1, HIGH);
digitalWrite(BY_2, HIGH);
digitalWrite(BG_1, HIGH);
digitalWrite(BG_2, HIGH);
}
if ((IRAval1>=1)&&(IRAval2>=1))
{digitalWrite(BY_1, HIGH);
digitalWrite(BY_2, LOW);
digitalWrite(BG_1, HIGH);
digitalWrite(BG_2, LOW);
}
tft.setTextSize(2);
tft.setTextColor(BLACK);
tft.setCursor(0, 0);
tft.fillScreen(WHITE);
tft.println("-------------------------"); // Static line 1
tft.println(" To select a Locomotive "); // Static line 2
tft.println(" Press the loco sched no "); // Static line 3
tft.println("-------------------------"); // Static line 1
}
int GetNumber()
{
char key = kpd.getKey();
if (key != NO_KEY)
{
switch (num)
if (num=0);
tft.setTextSize(2);
tft.setCursor(10, 50);
Serial.print(num);
tft.println("-------------------------"); // Static line 1
tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable back to 0°
tft.println(" 0 degrees selected "); // Variable line 3b - This will turn the turntable back to 0°
tft.println("-------------------------"); // Static line 1
delay (1000);
tft.println("-------------------------"); // Static line 1
tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's
tft.println("-------------------------"); // Static line 1
}
{
String getKey();
char key = kpd.getKey();
if (key != NO_KEY)
// break;
*** switch (confkey) ***
if (confkey='C'); // Confirm selection
StepMot.step(step0);
delay(dt);
digitalWrite(BY_1, HIGH);
digitalWrite(BY_2, HIGH);
tft.setTextColor(RED);
tft.println("-------------------------"); // Static line 1
tft.println("Standby bridge"); // Flashing RED while stepper motor are turning
tft.println(" are moving "); // Flashing RED while stepper motor are turning
tft.println("-------------------------"); // Static line 1
digitalWrite(BY_1, LOW);
digitalWrite(BY_2, LOW);
delay(500);
digitalWrite(BY_1, HIGH);
digitalWrite(BY_2, HIGH);
delay(500);
digitalWrite(BY_1, LOW);
digitalWrite(BY_2, LOW);
delay(500);
digitalWrite(BY_1, HIGH);
digitalWrite(BY_2, HIGH);
delay(500);
digitalWrite(BY_1, LOW);
digitalWrite(BY_2, LOW);
delay (3000);
tft.setTextColor(BLACK);
tft.println("-------------------------"); // Static line 1
tft.println("Bridge turned ");
tft.println(" to 0 degrees "); // To be displayed after the stepper motor is turned 180°
tft.println("-------------------------"); // Static line 1
digitalWrite(BY_1, LOW);
digitalWrite(BY_2, LOW);
ERROR:
switch quantity not an integer (*** problematic line ***)
I have read that "switch" may only be used for integers - BUT - what do you use to switch or move the input to a string?
Regard
To fix the compile time error change ...
switch (confkey)
to
switch (confkey.asInt())
That will extract the string's integer value for use in the switch statement.
Anything seems possible when you don't know what you're talking about.
@will Great - thanks a mil - however it is switch (confkey.toInt()) 🙂
Damn ! I simply can't function before my morning coffee 🙂
Anything seems possible when you don't know what you're talking about.
More problems I found on a quick scan. I presume some off these are due to this being a work in progress so you can ignore them (except for the last one which will bite you eventually 🙂
num - never set
confkey - never set
if ((IRAval1<=0)&&(IRAval2=0))
should be
if ((IRAval1<=0)&&(IRAval2==0))
the second equals turns it from an assignment to a logical test
Anything seems possible when you don't know what you're talking about.
@will thanks again.
String confkey;
int num;
I changed that strings as suggested. Should I change the second string as well?
if ((IRAval1>=1)&&(IRAval2>=1))
But I messed something up now bigtime - my screen keep scrolling...
Back to the drawing board...
No, the second test is valid because it's already in the form of a test with a logical result.
The problem with (IRAval2=0)) is that it SETS THE VALUE of IRAval2 TO zero. Adding the second equals changes that operation to a logical value (is IRAval2 equal to zero).
A subtle change but a huge difference. The expressions <,>,<=,>= don't correspond to any normal arithmetic operation and are easily recognized to have logical result values, but the distinction is required in the case of = because it does have a valid meaning in itself (i.e. value assignment).
Anything seems possible when you don't know what you're talking about.
May I ask another question please?
I have changed the sketch as follows:
void setup()
{
// Stepper PINS
//Definition of the pins, remember where you need
Serial.begin(9600);
StepMot.setSpeed(motSpeed);
tft.reset();
// IRA
pinMode(IRSensor1, INPUT);
pinMode(IRSensor2, INPUT);
// LCD
uint16_t id = tft.readID();
tft.begin(id);
tft.setRotation(1);
tft.fillScreen(WHITE);
tft.setTextColor(BLUE, WHITE);
// LED
pinMode (BY_1, OUTPUT);
pinMode (BY_2, OUTPUT);
pinMode (BG_1, OUTPUT);
pinMode (BG_2, OUTPUT);
// Initialize LCD
tft.setTextSize(2);
tft.setTextColor(BLACK);
tft.setCursor(0, 0);
tft.fillScreen(WHITE);
tft.println("-------------------------"); // Static line 1
tft.println(" To select a Locomotive "); // Static line 2
tft.println(" Press the loco sched no "); // Static line 3
tft.println("-------------------------"); // Static line 1
}
However, it seems it now forms an infinite loop, on the screen - the output on the serial monitor shows output from 1 to 8, then back to 1.
Any ideas - I also moved the screen initialize from the loop to the setup, to see if that solves it, but no luck.
You can ask as many questions as you want 🙂
It's impossible to answer this particular question though, because it seems that all you've shown us is the setup() and no loop().
It's the loop method that cycles, so the cause is most likely in there somewhere.
Also, your code is unindented and hard for us follow. To post code you should select the code in the Arduino IDE (usually select all) and then choose "copy as HTML" to copy the selected text. Then switch over to the browser and position the cursor about where you want the code. Then press return a couple of times to insert a couple of blank lines. Then click the "{;}" icon above the reply box (that'll put you in an HTML environment, so don't worry, you haven's screwed up when it goes all squirrelly) and position the cursor between a pair of <p></p> (the blank lines you made earlier) and paste the code in between a </p> and <p>.
If you click the Preview button below the reply box, you'll see how it will be displayed on the forum.
Anything seems possible when you don't know what you're talking about.
// LCDenKeyPad_Reg_LED's_Stepper //Keypad #include <Keypad.h> // Stepper #include <Stepper.h> // TFTLCD #include <MCUFRIEND_kbv.h> MCUFRIEND_kbv tft; // Stepper Motor - Model = 28BYJ-48 (Get from SPEC Sheet) int stepsPerRevolution=2048; int step0=0; int step1=15; int step2=45; int step3=75; int step4=105; int step5=-285; int step6=-255; int step7=-225; int step8=-195; int step9=180; int motSpeed=1; int dt=500; int deg0=0; int deg1=15; int deg2=45; int deg3=75; int deg4=105; int deg5=-285; int deg6=-255; int deg7=-225; int deg8=-195; int deg9=180; Stepper StepMot(stepsPerRevolution, 38,42,40,44); // LED Pins int BY_1 = 46; //Bridge Yellow 1 int BY_2 = 48; //Bridge Yellow 2 int BG_1 = 51; //Bridge Green 1 int BG_2 = 53; //Bridge Green 1 // IRA Sensors int IRSensor1=50; //Sensor 1 is setup on pin 2 int IRSensor2=52; //Sensor 2 is setup on pin 3 int IRAval1; int IRAval2; // Variable String confkey; int num; // Keypad const byte ROWS = 4; const byte COLS = 4; char Keys[ROWS][COLS] = { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; byte rowPins[ROWS] = {22, 24, 26, 28}; byte colPins[COLS] = {30, 32, 34, 36}; Keypad kpd = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS ); // TFTLCD float LCDRefreshTimer = 0; // Define Colours #define BLUE 0x001F #define WHITE 0xFFFF #define RED 0xF882 #define BLACK 0x0000 void setup() { // Stepper PINS //Definition of the pins, remember where you need Serial.begin(9600); StepMot.setSpeed(motSpeed); tft.reset(); // IRA pinMode(IRSensor1, INPUT); pinMode(IRSensor2, INPUT); // LCD uint16_t id = tft.readID(); tft.begin(id); tft.setRotation(1); tft.fillScreen(WHITE); tft.setTextColor(BLUE, WHITE); // LED pinMode (BY_1, OUTPUT); pinMode (BY_2, OUTPUT); pinMode (BG_1, OUTPUT); pinMode (BG_2, OUTPUT); // Initialize LCD tft.setTextSize(2); tft.setTextColor(BLACK); tft.setCursor(0, 0); tft.fillScreen(WHITE); tft.println("-------------------------"); // Static line 1 tft.println(" To select a Locomotive "); // Static line 2 tft.println(" Press the loco sched no "); // Static line 3 tft.println("-------------------------"); // Static line 1 } void loop() { num = GetNumber(); IRAval1 = digitalRead(IRSensor1); IRAval2 = digitalRead(IRSensor2); if ((IRAval1<=0)&&(IRAval2==0)) {digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); digitalWrite(BG_1, HIGH); digitalWrite(BG_2, HIGH); } if ((IRAval1>=1)&&(IRAval2>=1)) {digitalWrite(BY_1, HIGH); digitalWrite(BY_2, LOW); digitalWrite(BG_1, HIGH); digitalWrite(BG_2, LOW); } // StepMot.step(stepsPerRevolution); // delay(dt); // StepMot.step(-stepsPerRevolution); // delay(dt); } int GetNumber() { char key = kpd.getKey(); while (key != NO_KEY) { switch (num) if (num=0); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable back to 0° tft.println(" 0 degrees selected "); // Variable line 3b - This will turn the turntable back to 0° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step0); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 0° tft.println(" to 0 degrees "); // To be displayed after the stepper motor is turned 0° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { // else if (num=1); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable to 15° tft.println(" Loco Sched 1 selected "); // Variable line 3b - This will turn the turntable to 15° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step1); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 0° tft.println(" to Loco Sched 1 "); // To be displayed after the stepper motor is turned 0° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { if (num=2); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable to 45° tft.println(" Loco Sched 2 selected "); // Variable line 3b - This will turn the turntable to 45° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step2); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 45° tft.println(" to Loco Sched 2 "); // To be displayed after the stepper motor is turned 45° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { if (num=3); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable back to 0° tft.println(" Loco Sched 3 selected "); // Variable line 3b - This will turn the turntable back to 0° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step3); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 45° tft.println(" to Loco Sched 3 "); // To be displayed after the stepper motor is turned 45° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { if (num=4); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable back to 0° tft.println(" Loco Sched 5 selected "); // Variable line 3b - This will turn the turntable back to 0° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step4); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 45° tft.println(" to Loco Sched 4 "); // To be displayed after the stepper motor is turned 45° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { if (num=5); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable back to 0° tft.println(" Loco Sched 5 selected "); // Variable line 3b - This will turn the turntable back to 0° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step5); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 45° tft.println(" to Loco Sched 5 "); // To be displayed after the stepper motor is turned 45° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { if (num=6); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable back to 0° tft.println(" Loco Sched 6 selected "); // Variable line 3b - This will turn the turntable back to 0° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step6); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 45° tft.println(" to Loco Sched 6 "); // To be displayed after the stepper motor is turned 45° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { if (num=7); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable back to 0° tft.println(" Loco Sched 7 selected "); // Variable line 3b - This will turn the turntable back to 0° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step7); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 45° tft.println(" to Loco Sched 7 "); // To be displayed after the stepper motor is turned 45° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { if (num=8); tft.setTextSize(2); tft.setCursor(10, 50); Serial.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge move to "); // Variable line 3a - This will turn the turntable back to 0° tft.println(" Loco Sched 8 selected "); // Variable line 3b - This will turn the turntable back to 0° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step8); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 45° tft.println(" to Loco Sched 8 "); // To be displayed after the stepper motor is turned 45° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } { if (num=9); tft.setTextSize(2); tft.setCursor(10, 50); // tft.print(num); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turn to "); // Variable line 3a - This will turn the turntable back to 180° tft.println(" Bridge Exit selected "); // Variable line 3b - This will turn the turntable back to 180° tft.println("-------------------------"); // Static line 1 tft.println(" "); delay (1000); tft.println("-------------------------"); // Static line 1 tft.println(" Press C To Confirm "); // Pressing C will activate the stepper motor and turn on amber LED's and turn off green LED's tft.println("-------------------------"); // Static line 1 // Confirmation key String getKey(); char key = kpd.getKey(); if (key != NO_KEY) switch (confkey.toInt()) break; if (confkey='C'); // Confirm selection StepMot.step(step9); delay(dt); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); tft.setTextColor(RED); tft.println("-------------------------"); // Static line 1 tft.println(" Please wait - the "); // Flashing RED while stepper motor are turning tft.println(" bridge are moving "); // Flashing RED while stepper motor are turning tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay(500); digitalWrite(BY_1, HIGH); digitalWrite(BY_2, HIGH); delay(500); digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); delay (3000); tft.setTextColor(BLACK); tft.println("-------------------------"); // Static line 1 tft.println(" Bridge turned "); // To be displayed after the stepper motor is turned 45° tft.println(" to Exit "); // To be displayed after the stepper motor is turned 45° tft.println("-------------------------"); // Static line 1 digitalWrite(BY_1, LOW); digitalWrite(BY_2, LOW); } }
@will Nice - I see it have a option to copy for FORUM as well.
Yeah, but I've never seen that work very well 🙁
Anything seems possible when you don't know what you're talking about.
Anything seems possible when you don't know what you're talking about.
@will I tried to break it down into little bits, but it is too integrated...