Hello,
I am using a Nextion 7" Intelligent display, and Seithan's EasyNextion Library to control it. I have a very simple program to control a stepper motor. If a switch component is on, I want to turn the number of steps negative to get the stepper to go counter-clockwise, but just can't get it to work. I think it's probably syntax, but I've tried every permutation I can think of, and still no go. It just runs the code as if there were no minus sign. Any ideas?
#include <EasyNextionLibrary.h>
#include <trigger.h>
#include <Stepper.h>
EasyNex myNex(Serial);
int in1Pin = 8;
int in2Pin = 9;
int in3Pin = 10;
int in4Pin = 11;
Stepper motor(2048, in1Pin, in2Pin, in3Pin, in4Pin);
int numStp1 = 1;
int numStp2 = 0;
int numStp3 = 1;
uint32_t numSpd1 = 1;
uint32_t swClk;
void setup() {
myNex.begin(9600);// put your setup code here, to run once:
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
}
void loop() {
myNex.NextionListen();// put your main code here, to run repeatedly:
}
void trigger0() {
numStp1 = myNex.readNumber("sStp.val");
myNex.writeNum("nStp.val", numStp1 + numStp2);
}
void trigger1() {
numStp2 = myNex.readNumber("sStpG.val");
myNex.writeNum("nStp.val", numStp1 + numStp2);
}
void trigger2(){
numSpd1 = myNex.readNumber("sSpd.val");
myNex.writeNum("sSet.val", numSpd1);
}
void trigger5(){
swClk = myNex.readNumber("swCl.val");
if(swClk == 1)
{
numStp3 = myNex.readNumber("nStp.val");
(numStp3 * -1);
}
else(swClk == 0);
{
numStp3 = myNex.readNumber("nStp.val");
}
motor.setSpeed(numSpd1);
motor.step(numStp3);
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
}