Go Down

Topic: variable time using processing (Read 527 times) previous topic - next topic


Oct 15, 2007, 02:26 am Last Edit: Oct 15, 2007, 03:00 am by theoriginalryan Reason: 1
what would be the easiest way to program a time value into a sketch that is plugged in from a reading off a pot.  want to control the delay time between a solenoid going off, but leave the amount of time always the same.  i looking at trying to adapt the blink sketch, but can not find a good reference to do the variable time.


Oct 15, 2007, 03:38 am Last Edit: Oct 15, 2007, 04:07 am by theoriginalryan Reason: 1
this is what i came up with, but i think i need to change it not to use the delay function because i want to run other stuff on the board also(servo control).   Also, how would i output the value of the pot so i could make it a permanent value once i figure out what i should set it at.  I tired a couple ways but could not get it to output anything.

//solenoid control with pot

int potPin = 3;    // select the input pin for the potentiometer
int SolenoidPin = 13;   // Pin for the solenoid
int val = 0;       // variable to store pot value

void setup() {
 pinMode(SolenoidPin, OUTPUT);

void loop() {
 val = analogRead(potPin);    // read pot
 digitalWrite(SolenoidPin, HIGH);  // turn the solenoid on
 delay(20);                  // pause
 digitalWrite(SolenoidPin, LOW);   // turn the ledPin off
 delay(val+30);                  // pause with value from pot plus a min so the solenoid can not be constant on

Go Up