Back to Parent

Code for single particle. Copy code over for second, after switching events
int fan_pin = D0;
int motor_pin = D1;
int temp_pin = A0;
int default_temp = 0;


void setup() {
  // Setup I/O
  pinMode(fan_pin, OUTPUT);
  pinMode(motor_pin, OUTPUT);
  pinMode(temp_pin, INPUT);
  Serial.begin(9600);
  float default_temp = 0;
  // Subscribe to other photon event
  Particle.subscribe("breadthOnTwo", breadth_handler);
}

void loop() {
  float temp_cel = digitalRead(temp_pin);
  if (temp_cel > default_temp) {
   Particle.publish("breadthOnOne", String(temp_cel - default_temp));
 }
}


void breadth_handler(const char *event, const char *data) {
  // Release bubbles based on if being blown on on other end
  int activeF = 255;
  int activeM = 150;
  analogWrite(motor_pin, activeM);
  analogWrite(fan_pin, activeF);
  
  delay(1000);

  activeF = 0;
  activeM = 0;
  analogWrite(fan_pin, activeF);
  analogWrite(motor_pin, activeM);
 }
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0