Esempio n. 1
0
char* Component::read() {
  emptyReadValue();
  if(type==ANALOG || type==LIGHT || type==TEMP) {
    //in my country we call this code as "gambiarra" #Gambiarrafeelings
    //mas na verdade o sensor de temperatura analógico causa no ADC do ARduino! 
    state = analogRead(port);
    delay(5);
    state = analogRead(port);
    delay(5);
    state = analogRead(port);
    delay(5);
    return getValue();
  }
  else if(type==DIGITAL || type==RELAY || type==PWM) {
    //pinMode(port, INPUT);
    state = digitalRead(port);
    pinMode(port,OUTPUT);
    return getValue();
  } else if(type==SERIAL) {

    int counter=0; 
    while(Serial.available()>0 && counter<15) 
    {
      char c = Serial.read(); 
      delay(5);
      readValue[counter++]=c;
    }
    return readValue;
  } else if(type==CUSTOM) {
    //should call function pointer here..
    char* ccc="\0";
    return myCustomFunction(ccc);

  } else if(type==PING) {
    //Parallax ping based on digital pulseIn
    pinMode(port, OUTPUT);
    digitalWrite(port, LOW);
    delayMicroseconds(2);
    digitalWrite(port, HIGH);
    delayMicroseconds(5);
    digitalWrite(port, LOW);

    pinMode(port, INPUT);
    //long duration1 = pulseIn(port, HIGH);
    //long cm1 =  duration1 / 29 /2;
    //Serial.print("Duration: ");
    //Serial.println(duration1);
    //Serial.print("CM : ");
    //Serial.println(cm1);
    state = pulseIn(port, HIGH);
    return getValue();
  } 
  else return "\0";
}
Esempio n. 2
0
char* Component::write(char* c1) {
 char* r="\0";
 //debug Serial.println("DEntro do write... ");
 //debug Serial.println(c1);

 if(type==DIGITAL) {
   state = atoi(c1);
   digitalWrite(port, state);
   return r;
 }
 else if(type==PWM) {
   state = atoi(c1);
   analogWrite(port, atoi(c1));
   return r;
 }
 else if(type==CUSTOM) {
   return myCustomFunction(c1); 
 }
}
Esempio n. 3
0
char* Component::read() {
  emptyReadValue();
  if(type==ANALOG ) {
    //in my country we call this code as "gambiarra" #Gambiarrafeelings
    //mas na verdade o sensor de temperatura analógico causa no ADC do ARduino! 
    state = analogRead(port);
    delay(5);
    state = analogRead(port);
    delay(5);
    state = analogRead(port);
    delay(5);
    return getValue();
  }
  else if(type==DIGITAL || type==PWM) {
    //pinMode(port, INPUT);
    state = digitalRead(port);
    pinMode(port,OUTPUT);
    return getValue();
  } else if(type==SERIAL) {

    int counter=0; 
    while(Serial.available()>0 && counter<15) 
    {
      char c = Serial.read(); 
      delay(5);
      readValue[counter++]=c;
    }
    return readValue;
  } else if(type==CUSTOM) {
    //should call function pointer here..
    char* ccc="\0";
    return myCustomFunction(ccc);

  } 
  else return "\0";
}