Offline
Newbie
Karma: 0
Posts: 43
|
 |
« on: February 07, 2013, 03:28:07 pm » |
i want to have two or three inputs (pot,thermistor,switch) the pot and the thermistor need to tell how long it needs to say on and the switch just tells it when to turn on.
so like if pot is 125 and thermistor is at 336 than the output needs to stay on for 12ms or something like that, but no switch on till the switch reads high.
|
|
|
|
|
Logged
|
|
|
|
|
Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #1 on: February 07, 2013, 03:37:45 pm » |
First thing I'd do is establish the relationship between the pot value and the thermistor value value on the one hand, and the on-time on the other, ie on-time = f(pot-value, thermistor-value) (eg, like you say, if they are 125 and 336, on-time is 12) Then code something like this very-pseudo-code: read the pot read the thermistor on-time = ? // whatever the relationship is
read the switch if switch is high, set output-pin high and delay for on-time
|
|
|
|
|
Logged
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16572
Available for Design & Build services
|
 |
« Reply #2 on: February 07, 2013, 03:47:25 pm » |
Maybe something like this // declare variables, pinModes, etc.
void loop(){ delay(2); timeOne = analogRead(A0); delay(2); timeTwo = analogRead(A1); onTime = abs(timeOne - timeTwo); if (digitalRead(switchPin) == HIGH && timeRunning == 0){ timeRunning = 1; startTime = millis(); digitalWrite(ledPin, HIGH); endTime = startTime + onTime; } if ( timeRunning == 1 && (millis() >= endTime) ){ timeRunning = 0; digitalWrite(ledPin, LOW);} } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35590
Seattle, WA USA
|
 |
« Reply #3 on: February 07, 2013, 06:19:00 pm » |
Maybe something like this But properly indented...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #4 on: February 07, 2013, 07:20:05 pm » |
I was thinking maybe using a 2d array but im not sure how to use them. Have the range of a pot on one side and the range of the thermistor on the other side and the run time in ms in the table? im not at home so i can't test any of those sketches.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6406
-
|
 |
« Reply #5 on: February 07, 2013, 08:03:52 pm » |
I was thinking maybe using a 2d array but im not sure how to use them.
Do you really need to resort to a look-up table - can't you come up with an algorithm to calculate the time from the two input values?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16572
Available for Design & Build services
|
 |
« Reply #6 on: February 07, 2013, 09:56:21 pm » |
But properly indented... Yeah, I don't do indenting when I'm making it up on the fly and not home with the IDE.
|
|
|
|
« Last Edit: February 07, 2013, 10:10:27 pm by CrossRoads »
|
Logged
|
|
|
|
|
Anaheim CA.
Offline
Edison Member
Karma: 31
Posts: 2311
Experienced old Whitebeard with a Full head of Hair...
|
 |
« Reply #7 on: February 07, 2013, 10:08:27 pm » |
You Mr Crossroads, set a poor example... OTOH If he wrote code like I write letters.. No one could read it..
Bob
|
|
|
|
|
Logged
|
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #8 on: February 07, 2013, 10:09:39 pm » |
This is one probable answer
void setup(){ Serial.begin(9600); pinMode (pin, INPUT); }
void loop{ int pot = analogread(//pin); int thermoresistor = analogread(//pin); if (digitalRead(pin)==HIGH){ //your command }
}//end void loop
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16572
Available for Design & Build services
|
 |
« Reply #9 on: February 07, 2013, 10:12:46 pm » |
Indented sample code: // declare variables, pinModes, etc.
void loop(){ delay(2); timeOne = analogRead(A0); delay(2); timeTwo = analogRead(A1); onTime = abs(timeOne - timeTwo); if (digitalRead(switchPin) == HIGH && timeRunning == 0){ timeRunning = 1; startTime = millis(); digitalWrite(ledPin, HIGH); endTime = startTime + onTime; } if ( timeRunning == 1 && (millis() >= endTime) ){ timeRunning = 0; digitalWrite(ledPin, LOW); } }
|
|
|
|
|
Logged
|
|
|
|
|
Anaheim CA.
Offline
Edison Member
Karma: 31
Posts: 2311
Experienced old Whitebeard with a Full head of Hair...
|
 |
« Reply #10 on: February 07, 2013, 10:27:26 pm » |
Personally I like my curly's Right to the Wall. The Left wall that is...
|
|
|
|
|
Logged
|
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
|
|
|
|
Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #11 on: February 07, 2013, 11:12:05 pm » |
can't you come up with an algorithm to calculate the time from the two input values? That's what I was leaning towards with my on-time = f(pot-value, thermistor-value)This might be a good candidate for a fuzzy approach.....
|
|
|
|
|
Logged
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #12 on: February 09, 2013, 11:20:45 pm » |
Im not sure i think a look up table would ve better as it would help speed up reprograming. Just a 8 by 8 table would work fine. Any good tuts on that?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 15
Posts: 463
|
 |
« Reply #13 on: February 10, 2013, 12:42:37 am » |
i want to have two or three inputs (pot,thermistor,switch) the pot and the thermistor need to tell how long it needs to say on and the switch just tells it when to turn on.
so like if pot is 125 and thermistor is at 336 than the output needs to stay on for 12ms or something like that, but no switch on till the switch reads high.
It sounds like you are trying to make a closed loop temperature controller. If so, then using predefined values to control the "switch" will not work. It will be virtually impossible to get the right constants. That method would be "open loop". What you need to do is read your thermistor and turn the "switch" on for a time interval proportional to the DIFFERENCE between your "setpoint" (pot setting) and the actual reading (thermistor). The on time will get smaller and smaller until the setpoint it reached, then the circuit will just slowly kick the switch on and off to maintain the setpoint.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #14 on: February 10, 2013, 01:10:48 am » |
Its not to keep a constant temperature. Its to contol an injector. It needs to be adjustable to temperature change and how much the throttle body is opened and only open when it needs to.
|
|
|
|
|
Logged
|
|
|
|
|
|