Code for drippter
//Controls for the H bridge
int c1 = D0;
int c2 = D1;
int c3 = D2;
int c4 = D3;
//a speed of 1 indicates that painting should be taking place, and 0 that it should not
int diner1speed = 1;
int diner2speed = 0;
//These variables control the movement of the slider that moves the pipe pf the pump slowly across the painting
int movetime = 100;
int stoptime = 6000;
void setup()
{
pinMode(c1, OUTPUT);
pinMode(c2, OUTPUT);
pinMode(c3, OUTPUT);
pinMode(c4, OUTPUT);
Particle.subscribe("diotDimSum1On", diner1paint);
Particle.subscribe("diotDimSum1Off", diner1stop);
//Uncomment these in order to have the second painting also work
//Particle.subscribe("diotDimSum2On", diner2paint);
//Particle.subscribe("diotDimSum2Off", diner2stop);
Particle.variable("paint", &diner1speed, INT);
}
int diner1paint(const char * event, const char * data)
{
diner1speed = 1;
return 1;
}
int diner1stop(const char * event, const char * data)
{
diner1speed = 0;
return 1;
}
//Uncomment the following two function if there is a second diner
/*int diner2paint(const char * event, const char * data)
{
diner2speed = 1;
return 1;
}
int diner2stop(const char * event, const char * data)
{
diner2speed = 0;
return 1;
}*/
void loop()
{
if(diner1speed==1)
{
if(millis())
//Moves the pump
digitalWrite(c3, LOW);
digitalWrite(c4, HIGH);
//Moves the motor for movetime amount of time
digitalWrite(c1, LOW);
digitalWrite(c2, HIGH);
delay(movetime);
//Makes the motor stay still for stoptime amount of time
digitalWrite(c1, LOW);
digitalWrite(c2, LOW);
delay(stoptime);
}
else if (diner1speed ==0)
{
digitalWrite(c1, LOW);
digitalWrite(c2, LOW);
digitalWrite(c3, LOW);
digitalWrite(c4, LOW);
delay(100);
}
}
Aditi Chalisgaonkar
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .