part A: I am trying to have a green led light up (operation starts), servo moves object into place, yellow led light turns on while a machine operates part B: then once the object goes above a certain temperature it turns of the cleaner yellow led, the servo removes the part from the machine and the green led turns off.
my issue is the transition from part A and part B they both work perfectly but I cannot figure out how to get it to work I have tried several structures but nothing seems to make the program wait for the input then start part b
not sure how to make it in a second folder thingy I keep seeing on here but here is the code
#include <Servo.h>
/*
- How to wire this up.
- 5v and ground gets wired up to breadboard bus then the servo is wired to that
- the servo goes red to 5v bus, brown to ground bus and orange to pin 9
- the buttons led goes pin 4 to 220 ohm resistor to blue wire on the switch, then the red wire to ground
- the button is wired black to 5v bus, white wire to bread board and that connects to 3 things
- it connects to pin 3 and a 270 ohm resistor, the resistor is hooked to ground
- water pump indicator led pin 5 tp 220 ohm resistor to yellow led
*/
//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 4; //run indicator led
const int ledPin2 = 5; //water bath indicator led
bool start = false;
int buttonState = 0; // variable for reading the pushbutton status
int pos = 0; // variable to store the servo position
int temperatureF;
Servo myservo; // create servo object to control a servo
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() // run over and over again
{
readTmp36();
readStart();
readEnd();
}
void readTmp36()
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;
// print out the voltage
Serial.print(voltage); Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");
// now convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");
delay(1000); //waiting a second
}
void readStart()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(2000);
for (pos = 0; pos <= 180; pos += 1)
{ // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(100);
digitalWrite(ledPin2, HIGH);
start = true;
}
}
void readEnd()
{
if(start == true)
{
if(temperatureF > 75)
{
digitalWrite(ledPin2, LOW);
for (pos = 180; pos >= 0; pos -= 1)
{ // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(2000);
// turn LED off:
digitalWrite(ledPin, LOW);
start = false;
}
}
}