00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __WPROGRAM_H__
00024
00025 #include <WaspClasses.h>
00026 #endif
00027
00028
00029
00030 WaspSensorPrototyping::WaspSensorPrototyping()
00031 {
00032 pinMode(RELAY_PIN,OUTPUT);
00033 pinMode(SENS_PW_3V3,OUTPUT);
00034 pinMode(SENS_PW_5V,OUTPUT);
00035
00036 digitalWrite(RELAY_PIN,LOW);
00037 digitalWrite(SENS_PW_3V3,LOW);
00038 digitalWrite(SENS_PW_5V,LOW);
00039 }
00040
00041
00042
00043 void WaspSensorPrototyping::setBoardMode(uint8_t mode)
00044 {
00045 switch( mode )
00046 {
00047 case SENS_ON : digitalWrite(SENS_PW_3V3,HIGH);
00048 digitalWrite(SENS_PW_5V,HIGH);
00049
00050 RTC.setMode(RTC_ON);
00051 break;
00052 case SENS_OFF: digitalWrite(SENS_PW_3V3,LOW);
00053 digitalWrite(SENS_PW_5V,LOW);
00054 break;
00055 }
00056 }
00057
00058 void WaspSensorPrototyping::setRelayMode(uint8_t mode)
00059 {
00060 switch( mode )
00061 {
00062 case SENS_RELAY_ON : digitalWrite(RELAY_PIN,HIGH);
00063 break;
00064 case SENS_RELAY_OFF: digitalWrite(RELAY_PIN,LOW);
00065 break;
00066 }
00067 }
00068
00069 float WaspSensorPrototyping::readADC()
00070 {
00071 uint8_t valor[2] = {0, 0};
00072 float val_def;
00073 uint16_t val;
00074 uint8_t i = 0;
00075
00076 Wire.begin();
00077 Wire.requestFrom(B0010100, 2);
00078 while(Wire.available()){
00079 valor[i] = Wire.receive();
00080 i++;
00081 }
00082 PWR.closeI2C();
00083
00084 val = int(valor[0])*256 + int(valor[1]);
00085 val_def = (val - 32769)*9;
00086 val_def = val_def/65535;
00087
00088 return val_def;
00089 }
00090
00091 void WaspSensorPrototyping::setLoadResistor(float resistor)
00092 {
00093 uint8_t resist=0;
00094
00095 resist=(uint8_t) 128-(128/100)*resistor;
00096 Wire.begin();
00097 delay(100);
00098 Wire.beginTransmission(B0101000);
00099 Wire.send(B00000000);
00100 Wire.send(resist);
00101 Wire.endTransmission();
00102 PWR.closeI2C();
00103 }
00104
00105 void WaspSensorPrototyping::setAmplifierGain(float gain)
00106 {
00107 uint8_t ampli=0;
00108
00109 gain=(gain-1)*10;
00110 ampli=(uint8_t) 128-(128/100)*gain;
00111 Wire.begin();
00112 delay(100);
00113 Wire.beginTransmission(B0101000);
00114 Wire.send(B00010000);
00115 Wire.send(ampli);
00116 Wire.endTransmission();
00117 PWR.closeI2C();
00118 }
00119
00120 float WaspSensorPrototyping::readAnalogSensor(uint8_t pin)
00121 {
00122 uint16_t read_val;
00123 float def_val;
00124
00125 if ( (pin >= ANALOG1) && (pin <= ANALOG7) )
00126 {
00127 read_val = analogRead(pin);
00128 def_val = (read_val*3.3)/1023;
00129 return def_val;
00130 }
00131 else return -1;
00132 }
00133
00134
00135 WaspSensorPrototyping SensorProto=WaspSensorPrototyping();