Hi,
I have made a dashboard for my track car, and are trying to map the steppers.
The sensors are grounded, so I had to use a resistor and 5v to get a positive voltge.
Now the tempraturesensor gives lover voltage when getting warmer, so stepper goes wrong way. Could reversed the stepper, but then the Zeroing would go wrong way
Here is the full code
#include <SwitecX25.h>
#include <SoftwareSerial.h>
#define STEPS (315*3)
// Define some steppers and the pins the will use
SwitecX25 motor1(300,36,38,40,42);
SwitecX25 motor2(300,37,39,41,43);
float fval = 0.0;
int val = 0;
int ftemp = 0;
int temp = 0;
SoftwareSerial Serial7Segment(52, 53); //RX pin, TX pin
#define APOSTROPHE 5
#define COLON 4
#define DECIMAL4 3
#define DECIMAL3 2
#define DECIMAL2 1
#define DECIMAL1 0
long millisTimer;
byte seconds = 0;
byte minutes = 0;
byte hours = 0;
boolean amTime = true;
boolean colonOn = false;
char tempString[100]; //Used for sprintf
static int nextPos = 0;
void setup()
{
motor1.zero();
motor2.zero();
pinMode(12, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
Serial.println("OpenSegment Example Code");
Serial7Segment.begin(9600); //Talk to the Serial7Segment at 9600 bps
Serial7Segment.write('v'); //Reset the display - this forces the cursor to return to the beginning of the display
delay(3000);
}
void loop()
{
// the motor only moves when you call update
float temp = (map(analogRead(A0), 900, 0, 0, 300));
motor1.setPosition(temp);
motor1.update();
motor2.setPosition(map(analogRead(A1), 0, 900, 0, 300));
motor2.update();
Serial.print(temp);
delay(100);
float fval = (map(analogRead(A2), 0, 1023, 355, 1023) / 1023.0) * 22.5;
val = fval*100;
if ((val >=1470) || (val<= 1469))digitalWrite(2, HIGH);
else digitalWrite(2, LOW);
if ((val >=1450) || (val<= 1400))digitalWrite(3, HIGH);
else digitalWrite(3, LOW);
if ((val >=1500) || (val<= 1350))digitalWrite(4, HIGH);
else digitalWrite(4, LOW);
if ((val >=1550) || (val<= 1300))digitalWrite(5, HIGH);
else digitalWrite(5, LOW);
if ((val >=1600) || (val<= 1200))digitalWrite(6, HIGH);
else digitalWrite(6, LOW);
if ((val >=1650) || (val<= 1100))digitalWrite(7, HIGH);
else digitalWrite(7, LOW);
if ((val >=1700) || (val<= 1000))digitalWrite(8, HIGH);
else digitalWrite(8, LOW);
if ((val >=1750) || (val<= 950))digitalWrite(9, HIGH);
else digitalWrite(9, LOW);
if ((val >=1800) || (val<= 900))digitalWrite(10, HIGH);
else digitalWrite(10, LOW);
if ((val >=1850) || (val<= 850))digitalWrite(11, HIGH);
else digitalWrite(11, LOW);
//Serial.print(val);
//Serial.println(val);
colonOn = true;
Serial7Segment.write(0x77); // Decimal, colon, apostrophe control command
Serial7Segment.write( (1<<APOSTROPHE) | (1<<COLON) | (1<<DECIMAL2) ); // Turns on colon, apostrophoe, and far-right decimal
char tempString[4]; //Used for sprintf
sprintf(tempString, "%4d", val); //Convert deciSecond into a string that is right adjusted
//sprintf(tempString, "%d", val); //Convert deciSecond into a string that is left adjusted (requires digit 1 command)
//sprintf(tempString, "%04d", val); //Convert deciSecond into a string with leading zeros
//sprintf(tempString, "%4X", val); //Count in HEX, right adjusted
//int negativeCycles = cycles * -1;
//sprintf(tempString, "%4d", negativeCycles); //Shows a negative sign infront of right adjusted number
//Note: This method works well as long as your number is less than or equal to 4 digits.
//14422 will cause the display to wrap (5 digits)
//-5766 will cause the display to wrap (5 digits)
//To fix this, send a 'v' character or look at how to control the digit placement
//https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Basic-Usage#wiki-cursor
Serial7Segment.print(tempString); //Send serial string out the soft serial port to the S7S
delay(10);
}