I am trying to drive a digipot with a duration time i receive from my timer. I would like to use the input from 2 potentiometers to set the thresholds. I have built the circuit and the arduino is running the code i have created so far to connect to the digipot, read the timers and read the pots but I'm a little lost as to how i would tie the rest of it together. Any help would be greatly appreciated.
these would be the thresholds to the 2 pots
const int POTL
const int lowlow = 5000
const int lowhigh = 3000
const int POTH
const int highlow = 3000
const int highhigh = 1000
#include <Adafruit_DS3502.h>
Adafruit_DS3502 ds3502 = Adafruit_DS3502();
#define WIPER_VALUE_PIN A0
byte button = 2;
unsigned long startTime;
unsigned long endTime;
unsigned long duration;
unsigned long timerMillis;
byte timerRunning;
const int POTL = 1; // Pot on Analog Pin 1
const int POTH = 2; // Pot on Analog Pin 2
int lowspeed = 0; // Low speed set
int highspeed = 0; // High Speed set
int lowrpm = 0; // Low RPM kick in
int highrpm = 0; // High RPM kick in
const int lowlow = 5000
const int lowhigh = 3000
const int highlow = 3000
const int highhigh = 1000
void setup() {
pinMode (button, INPUT);
Serial.begin(9600);
while (!Serial) {
delay(1);
}
Serial.println("Adafruit DS3502 Test");
if (!ds3502.begin()) {
Serial.println("Couldn't find DS3502 chip");
while (1);
}
Serial.println("Found DS3502 chip");
}
void loop()
{
if (timerRunning == 0 && digitalRead(button) == HIGH) {
startTime = millis();
timerRunning = 1;
timerMillis = millis();
}
if (timerRunning == 1 && digitalRead(button) == LOW) {
endTime = millis();
timerRunning = 0;
duration = endTime - startTime;
lowspeed = analogRead(POTL);
highspeed = analogRead(POTH);
Serial.print("LOW ");
Serial.print(lowspeed);
Serial.print("\t\t");
Serial.print("HIGH ");
Serial.println(highspeed); Serial.print ("time in milliseconds: ");
Serial.println (duration);
}
if (timerRunning == 1 && millis() - timerMillis >= 5000)
{
timerRunning = 0;
duration = 5000;
lowspeed = analogRead(POTL);
highspeed = analogRead(POTH);
Serial.print("LOW ");
Serial.print(lowspeed);
Serial.print("\t\t");
Serial.print("HIGH ");
Serial.println(highspeed); Serial.print ("time in milliseconds: ");
Serial.println (duration);
}
}
Sorry i was setting up here for the complete project now that i have the timer part sorted. Im just learning my way around the arduino landscape. I have added
ds3502.setWiper(0);
to the start of the loop
That is just so i can see the outputs that i am getting while i build the mechanical side of the machine and figure out the finer details of where i need to set the parameters. the finished program won't need to output any information to the serial monitor just drive the digipot according to the time interval
We cannot see where the top red and blue power rails are connected to the bottom red and blue power rails.
The black sensor (?) cable looks like it is connected between Pin D2 and GND with a switch connected between GND and D2. There is a resistor from D2 to the red power rail. This is contrary to your schematic ?
The switch being connect from D2 to GND means a closed switch is a LOW, not a HIGH: if (timerRunning == 0 && digitalRead(button) == HIGH)
Sorry that schematic is a little out of date from before i had the breakout board, i have updated and will include.
The wheel sensor is a simple magnetic switch from a bike computer that is being used to pick up the speed of the crank on a stationary bike.
A4 an A5 are not connected to 5V as per updated drawing.
The push button is just to replicate the wheel sensor when im not connecter to the actual bike.
I want to use the 2 potentiometers to adjust the lower and upper limit of where i will map the digipot too.
The pedal box just contains the actual potentiometer that im replacing with the digipot.
Both sets of rails on the breadboard are connected the the Arduino.
Everything is working, the timer works as needed and i can set the digipot but im not sure how i go about writing the code to map the pots to their time variables POTL (lowlow - low high) POTH (highlow - high high) and then have those mapped to the digipot according to the duration var
The manual pots will determine the range of the timing,
say POTL is set all the way down (lowlow) and POTH is all the way down (highlow) if the timer was 5000 the digipot wiper would be a 0 and if the timer was at 3000 it would set the wiper to 127, if POTH was all the way to (highhigh) then it would take the timer to be at 1000 to get to the wiper to 127 so at all times the wiper has full range but how it determines the timer is set by the pots
const int lowlow = 5000;
const int lowhigh = 3000;
const int highlow = 3000;
const int highhigh = 1000;
What happens if:
say POTL is set all the way down (lowlow 5000) and POTH is all the way down (highlow 3000) if the timer was 5000 the digipot wiper would be a 0 and if the timer was at 3000 it would set the wiper to 127 And if the timer was 1000, what would the wiper be set to ?
What happens if:
if POTH was all the way to (highhigh 1000) and the timer was 500, what would the wiper be set to ?
What happens if:
say POTL is set all the way down (lowHIGH 3000) and POTH is all the way down (highlow 3000) And if the timer was 3000, what would the wiper be set to ?
It's looking pretty good, thank you for your help. Im going to be focused on building the mechanical side of the machine now so i'll come back here if i have any problems as it all comes together