Pins - On/Off
hi - i'm trying write program turns switch on , off (one connected air compressor, vacuum) serial port. able turn vacuum on, not off, if first turn on, allow delay , turn off.
my code below:
const byte air = 9; //z-axis
const byte vac = 10; //vacuum
void setup()
{
// initialize digital pin 12 output.
// initialize digital pin 13 output.
pinmode(air, output);
pinmode(vac, output);
serial.begin(115200);
}
void loop()
{
char x= serial.read();
while (x == 'a' || x == 'b')
{
if (x == 'a')
{
zmotionon();
suctionon();
}
if (x == 'b')
{
zmotionoff();
suctionoff();
}
}
}
void zmotionon()
{
digitalwrite(air, high); // extend air cylinder
delay(3000); // wait second
}
void suctionon()
{
digitalwrite(vac, high); // open vacuum line manifold
delay(3000); // wait second
}
void zmotionoff()
{
digitalwrite(air, low); // retract air cylinder
delay(3000); // wait second
}
void suctionoff()
{
digitalwrite(vac, high); // open vacuum line manifold
delay(1000); // wait second
digitalwrite(vac, low); // shut off vacuum line manifold
delay(3000); // wait second
}
my code below:
const byte air = 9; //z-axis
const byte vac = 10; //vacuum
void setup()
{
// initialize digital pin 12 output.
// initialize digital pin 13 output.
pinmode(air, output);
pinmode(vac, output);
serial.begin(115200);
}
void loop()
{
char x= serial.read();
while (x == 'a' || x == 'b')
{
if (x == 'a')
{
zmotionon();
suctionon();
}
if (x == 'b')
{
zmotionoff();
suctionoff();
}
}
}
void zmotionon()
{
digitalwrite(air, high); // extend air cylinder
delay(3000); // wait second
}
void suctionon()
{
digitalwrite(vac, high); // open vacuum line manifold
delay(3000); // wait second
}
void zmotionoff()
{
digitalwrite(air, low); // retract air cylinder
delay(3000); // wait second
}
void suctionoff()
{
digitalwrite(vac, high); // open vacuum line manifold
delay(1000); // wait second
digitalwrite(vac, low); // shut off vacuum line manifold
delay(3000); // wait second
}
tell how out of while loop.
Arduino Forum > Using Arduino > Programming Questions > Pins - On/Off
arduino
Comments
Post a Comment