![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
wss
Dependencies: mbed Adafruit_GFX DS1820
main.cpp@17:74282523ba3e, 2021-12-14 (annotated)
- Committer:
- davidmateos
- Date:
- Tue Dec 14 18:48:15 2021 +0000
- Revision:
- 17:74282523ba3e
- Parent:
- 16:d49a029f2a1b
hgh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
javiervicente | 0:8a1a447db446 | 1 | #include "mbed.h" |
javiervicente | 0:8a1a447db446 | 2 | #include "hcsr04.h" |
davidmateos | 10:db8ef252faba | 3 | #include "DS1820.h" |
davidmateos | 8:a071c579f9ea | 4 | |
davidmateos | 8:a071c579f9ea | 5 | |
davidmateos | 6:23dfd7b0e58c | 6 | #include "Adafruit_SSD1306.h" |
davidmateos | 14:21cb6b2ac16b | 7 | |
davidmateos | 6:23dfd7b0e58c | 8 | class I2CPreInit : public I2C |
davidmateos | 6:23dfd7b0e58c | 9 | { |
davidmateos | 6:23dfd7b0e58c | 10 | public: |
davidmateos | 6:23dfd7b0e58c | 11 | I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl) |
davidmateos | 6:23dfd7b0e58c | 12 | { |
davidmateos | 6:23dfd7b0e58c | 13 | frequency(100000); |
davidmateos | 6:23dfd7b0e58c | 14 | start(); |
davidmateos | 6:23dfd7b0e58c | 15 | }; |
davidmateos | 6:23dfd7b0e58c | 16 | }; |
davidmateos | 14:21cb6b2ac16b | 17 | |
davidmateos | 14:21cb6b2ac16b | 18 | |
davidmateos | 6:23dfd7b0e58c | 19 | I2CPreInit gI2C(PB_9,PB_8); |
davidmateos | 14:21cb6b2ac16b | 20 | |
davidmateos | 6:23dfd7b0e58c | 21 | // an SPI sub-class that provides a constructed default |
davidmateos | 14:21cb6b2ac16b | 22 | |
davidmateos | 6:23dfd7b0e58c | 23 | Adafruit_SSD1306_I2c gOled(gI2C,NC,0x78,64,128); |
davidmateos | 9:d651ed116942 | 24 | |
daniferca | 1:1e68e882342d | 25 | |
javiervicente | 0:8a1a447db446 | 26 | Serial pc(USBTX, USBRX); // tx, rx |
davidmateos | 13:d2c49ef3b2ac | 27 | //Serial bt(D1, D0); // tx, rx |
davidmateos | 13:d2c49ef3b2ac | 28 | |
davidmateos | 13:d2c49ef3b2ac | 29 | |
javiervicente | 0:8a1a447db446 | 30 | Ticker tickerMideDistancia; |
davidmateos | 4:aa8a5a606384 | 31 | unsigned distancia=20; |
javiervicente | 0:8a1a447db446 | 32 | |
daniferca | 1:1e68e882342d | 33 | HCSR04 usensor(D7,D8); //(PinName TrigPin,PinName EchoPin): |
daniferca | 2:828e6ac4800a | 34 | DigitalIn finalDer(D2); |
daniferca | 2:828e6ac4800a | 35 | DigitalIn finalIzq(D3); |
davidmateos | 15:2acad1c57ad4 | 36 | DigitalIn boton(D5); |
davidmateos | 16:d49a029f2a1b | 37 | DigitalIn switcher(D9); |
javiervicente | 0:8a1a447db446 | 38 | DigitalOut step(D13); |
javiervicente | 0:8a1a447db446 | 39 | DigitalOut dir(D12); |
javiervicente | 0:8a1a447db446 | 40 | DigitalOut enable(D11); |
davidmateos | 14:21cb6b2ac16b | 41 | DigitalOut led(LED1); |
davidmateos | 14:21cb6b2ac16b | 42 | DS1820 ds1820(D10); // substitute PA_9 with actual mbed pin name connected to the DS1820 data pin |
davidmateos | 11:ff1efbab2d9e | 43 | |
davidmateos | 11:ff1efbab2d9e | 44 | //gitalOut rele(A5); |
davidmateos | 14:21cb6b2ac16b | 45 | |
davidmateos | 10:db8ef252faba | 46 | float temp = 0; |
davidmateos | 5:0e6b049208d8 | 47 | int contador=0; |
davidmateos | 17:74282523ba3e | 48 | int taladro =0; |
davidmateos | 13:d2c49ef3b2ac | 49 | |
davidmateos | 15:2acad1c57ad4 | 50 | int x=0; |
davidmateos | 15:2acad1c57ad4 | 51 | int y=0; |
davidmateos | 13:d2c49ef3b2ac | 52 | //if (x==1){ |
davidmateos | 14:21cb6b2ac16b | 53 | //y=0; |
davidmateos | 14:21cb6b2ac16b | 54 | // }else{ |
davidmateos | 14:21cb6b2ac16b | 55 | // y=1; |
davidmateos | 14:21cb6b2ac16b | 56 | // } |
davidmateos | 13:d2c49ef3b2ac | 57 | |
davidmateos | 11:ff1efbab2d9e | 58 | //////////////// |
davidmateos | 11:ff1efbab2d9e | 59 | Timer tiempo; |
davidmateos | 5:0e6b049208d8 | 60 | |
javiervicente | 0:8a1a447db446 | 61 | enum estados {cerrada, abriendose, cerrandose, abierta}; |
javiervicente | 0:8a1a447db446 | 62 | estados estado; |
javiervicente | 0:8a1a447db446 | 63 | |
javiervicente | 0:8a1a447db446 | 64 | |
javiervicente | 0:8a1a447db446 | 65 | void mideDistancia() |
javiervicente | 0:8a1a447db446 | 66 | { |
javiervicente | 0:8a1a447db446 | 67 | usensor.start(); |
javiervicente | 0:8a1a447db446 | 68 | } |
javiervicente | 0:8a1a447db446 | 69 | |
javiervicente | 0:8a1a447db446 | 70 | void paso(int d) |
javiervicente | 0:8a1a447db446 | 71 | { |
javiervicente | 0:8a1a447db446 | 72 | dir=d; |
javiervicente | 0:8a1a447db446 | 73 | step=1; |
daniferca | 2:828e6ac4800a | 74 | wait_us(100); // Este es el cambio de paso |
javiervicente | 0:8a1a447db446 | 75 | step=0; |
daniferca | 2:828e6ac4800a | 76 | wait_us(900); //Este hay que cambiar |
javiervicente | 0:8a1a447db446 | 77 | } |
javiervicente | 0:8a1a447db446 | 78 | |
javiervicente | 0:8a1a447db446 | 79 | void estadoCerrada() |
javiervicente | 0:8a1a447db446 | 80 | { |
davidmateos | 15:2acad1c57ad4 | 81 | |
davidmateos | 15:2acad1c57ad4 | 82 | if (x==1) { |
davidmateos | 14:21cb6b2ac16b | 83 | if( (finalIzq == 1) && contador <3) { |
davidmateos | 14:21cb6b2ac16b | 84 | wait(0.5); |
davidmateos | 14:21cb6b2ac16b | 85 | enable=1; |
davidmateos | 14:21cb6b2ac16b | 86 | estado=abriendose; |
davidmateos | 14:21cb6b2ac16b | 87 | // pc.printf("Distance =%d\n",distancia); |
davidmateos | 14:21cb6b2ac16b | 88 | pc.printf("Final2 pulsado\r\n"); |
davidmateos | 14:21cb6b2ac16b | 89 | |
davidmateos | 14:21cb6b2ac16b | 90 | |
davidmateos | 14:21cb6b2ac16b | 91 | //distancia < 5 |
davidmateos | 16:d49a029f2a1b | 92 | } //else if(contador==3) { |
davidmateos | 16:d49a029f2a1b | 93 | // x=0; |
davidmateos | 16:d49a029f2a1b | 94 | //y=1; |
davidmateos | 16:d49a029f2a1b | 95 | //contador=0; |
davidmateos | 16:d49a029f2a1b | 96 | //} |
davidmateos | 11:ff1efbab2d9e | 97 | } |
davidmateos | 15:2acad1c57ad4 | 98 | if(x==0 &&y==0) { |
davidmateos | 11:ff1efbab2d9e | 99 | pc.printf("No seleccionado programa\r\n"); |
davidmateos | 14:21cb6b2ac16b | 100 | } |
davidmateos | 14:21cb6b2ac16b | 101 | |
davidmateos | 14:21cb6b2ac16b | 102 | |
davidmateos | 15:2acad1c57ad4 | 103 | if(y==1) { |
davidmateos | 17:74282523ba3e | 104 | if(boton==1){ |
davidmateos | 17:74282523ba3e | 105 | taladro=0; |
davidmateos | 17:74282523ba3e | 106 | } |
davidmateos | 17:74282523ba3e | 107 | if( (finalIzq == 1) && (boton==1)) { |
davidmateos | 17:74282523ba3e | 108 | enable=1; |
davidmateos | 17:74282523ba3e | 109 | estado=abriendose; |
davidmateos | 17:74282523ba3e | 110 | |
davidmateos | 17:74282523ba3e | 111 | } |
davidmateos | 14:21cb6b2ac16b | 112 | |
davidmateos | 17:74282523ba3e | 113 | |
davidmateos | 17:74282523ba3e | 114 | else if (taladro>0 && taladro <6){ |
davidmateos | 17:74282523ba3e | 115 | |
davidmateos | 17:74282523ba3e | 116 | estado=abriendose; |
davidmateos | 17:74282523ba3e | 117 | |
davidmateos | 17:74282523ba3e | 118 | |
davidmateos | 17:74282523ba3e | 119 | } |
davidmateos | 17:74282523ba3e | 120 | tiempo.reset(); |
davidmateos | 17:74282523ba3e | 121 | tiempo.start(); |
davidmateos | 17:74282523ba3e | 122 | |
davidmateos | 14:21cb6b2ac16b | 123 | |
davidmateos | 14:21cb6b2ac16b | 124 | |
javiervicente | 0:8a1a447db446 | 125 | } |
davidmateos | 17:74282523ba3e | 126 | } |
javiervicente | 0:8a1a447db446 | 127 | |
javiervicente | 0:8a1a447db446 | 128 | void estadoAbriendose() |
javiervicente | 0:8a1a447db446 | 129 | { |
davidmateos | 14:21cb6b2ac16b | 130 | |
davidmateos | 15:2acad1c57ad4 | 131 | if(x==1) { |
davidmateos | 14:21cb6b2ac16b | 132 | //pc.printf("Distance =%d\n",distancia); |
davidmateos | 14:21cb6b2ac16b | 133 | if((finalDer==1)) { |
davidmateos | 14:21cb6b2ac16b | 134 | |
davidmateos | 14:21cb6b2ac16b | 135 | estado=abierta; |
davidmateos | 14:21cb6b2ac16b | 136 | enable=0; |
davidmateos | 14:21cb6b2ac16b | 137 | |
davidmateos | 14:21cb6b2ac16b | 138 | } else { |
davidmateos | 14:21cb6b2ac16b | 139 | gOled.clearDisplay(); |
davidmateos | 14:21cb6b2ac16b | 140 | |
davidmateos | 14:21cb6b2ac16b | 141 | paso(1); |
davidmateos | 14:21cb6b2ac16b | 142 | //pc.printf("paso\n"); |
davidmateos | 14:21cb6b2ac16b | 143 | |
davidmateos | 14:21cb6b2ac16b | 144 | } |
davidmateos | 11:ff1efbab2d9e | 145 | } |
davidmateos | 14:21cb6b2ac16b | 146 | // if (distancia<4){ |
davidmateos | 14:21cb6b2ac16b | 147 | //estado=cerrandose; |
davidmateos | 14:21cb6b2ac16b | 148 | |
davidmateos | 17:74282523ba3e | 149 | |
davidmateos | 15:2acad1c57ad4 | 150 | if(y==1) { |
davidmateos | 14:21cb6b2ac16b | 151 | |
davidmateos | 17:74282523ba3e | 152 | if(tiempo.read() > 3 ){ |
davidmateos | 17:74282523ba3e | 153 | |
davidmateos | 17:74282523ba3e | 154 | taladro++; |
davidmateos | 17:74282523ba3e | 155 | estado=abierta; |
davidmateos | 17:74282523ba3e | 156 | enable=0; |
davidmateos | 17:74282523ba3e | 157 | |
davidmateos | 17:74282523ba3e | 158 | } |
davidmateos | 17:74282523ba3e | 159 | |
davidmateos | 17:74282523ba3e | 160 | else if ((taladro>0) && (tiempo.read() > 0.6)){ |
davidmateos | 17:74282523ba3e | 161 | |
davidmateos | 17:74282523ba3e | 162 | taladro++; |
davidmateos | 17:74282523ba3e | 163 | estado=abierta; |
davidmateos | 17:74282523ba3e | 164 | enable=0; |
davidmateos | 17:74282523ba3e | 165 | } |
davidmateos | 17:74282523ba3e | 166 | else { |
davidmateos | 17:74282523ba3e | 167 | |
davidmateos | 17:74282523ba3e | 168 | paso(1); |
davidmateos | 17:74282523ba3e | 169 | |
davidmateos | 17:74282523ba3e | 170 | } |
davidmateos | 14:21cb6b2ac16b | 171 | |
davidmateos | 14:21cb6b2ac16b | 172 | } |
davidmateos | 14:21cb6b2ac16b | 173 | |
davidmateos | 14:21cb6b2ac16b | 174 | |
javiervicente | 0:8a1a447db446 | 175 | } |
javiervicente | 0:8a1a447db446 | 176 | |
davidmateos | 14:21cb6b2ac16b | 177 | void estadoCerrandose() |
davidmateos | 14:21cb6b2ac16b | 178 | { |
davidmateos | 14:21cb6b2ac16b | 179 | //pc.printf("Distance =%d\n",distancia); |
davidmateos | 15:2acad1c57ad4 | 180 | if(x==1) { |
davidmateos | 14:21cb6b2ac16b | 181 | if((finalIzq==1)) { |
davidmateos | 14:21cb6b2ac16b | 182 | |
davidmateos | 14:21cb6b2ac16b | 183 | estado=cerrada; |
davidmateos | 14:21cb6b2ac16b | 184 | enable=0; |
davidmateos | 14:21cb6b2ac16b | 185 | } else { |
davidmateos | 14:21cb6b2ac16b | 186 | |
davidmateos | 14:21cb6b2ac16b | 187 | paso(0); |
davidmateos | 14:21cb6b2ac16b | 188 | //pc.printf("paso\n"); |
davidmateos | 14:21cb6b2ac16b | 189 | |
davidmateos | 14:21cb6b2ac16b | 190 | } |
javiervicente | 0:8a1a447db446 | 191 | } |
davidmateos | 17:74282523ba3e | 192 | if (y==1){ |
davidmateos | 17:74282523ba3e | 193 | if((tiempo.read() > 0.6) && taladro<6) { |
davidmateos | 17:74282523ba3e | 194 | |
davidmateos | 17:74282523ba3e | 195 | |
davidmateos | 17:74282523ba3e | 196 | estado=cerrada; |
davidmateos | 17:74282523ba3e | 197 | } |
davidmateos | 17:74282523ba3e | 198 | |
davidmateos | 17:74282523ba3e | 199 | else if ((taladro==6)&& (finalIzq==1)){ |
davidmateos | 17:74282523ba3e | 200 | |
davidmateos | 17:74282523ba3e | 201 | estado = cerrada; |
davidmateos | 17:74282523ba3e | 202 | enable = 0; |
davidmateos | 17:74282523ba3e | 203 | contador=0; |
davidmateos | 17:74282523ba3e | 204 | } |
davidmateos | 17:74282523ba3e | 205 | |
davidmateos | 17:74282523ba3e | 206 | |
davidmateos | 17:74282523ba3e | 207 | else { |
davidmateos | 17:74282523ba3e | 208 | |
davidmateos | 17:74282523ba3e | 209 | paso(0); |
davidmateos | 17:74282523ba3e | 210 | |
davidmateos | 17:74282523ba3e | 211 | } |
davidmateos | 17:74282523ba3e | 212 | } |
davidmateos | 14:21cb6b2ac16b | 213 | |
davidmateos | 14:21cb6b2ac16b | 214 | |
javiervicente | 0:8a1a447db446 | 215 | } |
javiervicente | 0:8a1a447db446 | 216 | |
javiervicente | 0:8a1a447db446 | 217 | void estadoAbierta() |
javiervicente | 0:8a1a447db446 | 218 | { |
davidmateos | 4:aa8a5a606384 | 219 | //pc.printf("Distance =%d\n",distancia); |
davidmateos | 5:0e6b049208d8 | 220 | //if (finalDer==1) { |
davidmateos | 14:21cb6b2ac16b | 221 | |
davidmateos | 17:74282523ba3e | 222 | if (x==1){ |
davidmateos | 14:21cb6b2ac16b | 223 | enable=1; |
davidmateos | 14:21cb6b2ac16b | 224 | estado=cerrandose; |
davidmateos | 14:21cb6b2ac16b | 225 | pc.printf("Final1 pulsado\r\n"); |
davidmateos | 14:21cb6b2ac16b | 226 | |
davidmateos | 5:0e6b049208d8 | 227 | //} |
davidmateos | 5:0e6b049208d8 | 228 | contador++; |
davidmateos | 9:d651ed116942 | 229 | gOled.clearDisplay(); |
davidmateos | 9:d651ed116942 | 230 | gOled.printf("piezas transportadas %d\n",contador); |
davidmateos | 13:d2c49ef3b2ac | 231 | gOled.printf("temp = %3.1f C\r\n", temp); |
davidmateos | 9:d651ed116942 | 232 | gOled.display(); |
davidmateos | 14:21cb6b2ac16b | 233 | gOled.setTextCursor(0,0); |
davidmateos | 15:2acad1c57ad4 | 234 | pc.printf("temp = %3.1f C\r\n", temp); |
davidmateos | 17:74282523ba3e | 235 | } |
davidmateos | 14:21cb6b2ac16b | 236 | |
davidmateos | 17:74282523ba3e | 237 | if(y==1){ |
davidmateos | 17:74282523ba3e | 238 | tiempo.reset(); |
davidmateos | 17:74282523ba3e | 239 | tiempo.start(); |
davidmateos | 17:74282523ba3e | 240 | |
davidmateos | 17:74282523ba3e | 241 | enable=1; |
davidmateos | 17:74282523ba3e | 242 | estado=cerrandose; |
davidmateos | 17:74282523ba3e | 243 | } |
davidmateos | 14:21cb6b2ac16b | 244 | |
javiervicente | 0:8a1a447db446 | 245 | } |
javiervicente | 0:8a1a447db446 | 246 | |
javiervicente | 0:8a1a447db446 | 247 | int main() |
javiervicente | 0:8a1a447db446 | 248 | { |
javiervicente | 0:8a1a447db446 | 249 | pc.baud(115200); |
javiervicente | 0:8a1a447db446 | 250 | tickerMideDistancia.attach(&mideDistancia, 0.5); |
javiervicente | 0:8a1a447db446 | 251 | estado=cerrada; |
davidmateos | 14:21cb6b2ac16b | 252 | gOled.begin(); |
davidmateos | 9:d651ed116942 | 253 | gOled.clearDisplay(); |
davidmateos | 14:21cb6b2ac16b | 254 | gOled.printf("Hola\n"); |
davidmateos | 14:21cb6b2ac16b | 255 | gOled.display(); |
davidmateos | 14:21cb6b2ac16b | 256 | //x=(pc.getc()); |
davidmateos | 4:aa8a5a606384 | 257 | //pc.printf("Estado cerrada\n"); |
davidmateos | 15:2acad1c57ad4 | 258 | |
davidmateos | 15:2acad1c57ad4 | 259 | if (boton ==1){ |
davidmateos | 16:d49a029f2a1b | 260 | contador=0; |
davidmateos | 15:2acad1c57ad4 | 261 | } |
davidmateos | 15:2acad1c57ad4 | 262 | |
davidmateos | 15:2acad1c57ad4 | 263 | |
davidmateos | 14:21cb6b2ac16b | 264 | if(x==1) { |
davidmateos | 11:ff1efbab2d9e | 265 | gOled.clearDisplay(); |
davidmateos | 14:21cb6b2ac16b | 266 | gOled.printf("Programa de transporte de piezas\n"); |
davidmateos | 14:21cb6b2ac16b | 267 | gOled.display(); |
davidmateos | 14:21cb6b2ac16b | 268 | } |
davidmateos | 14:21cb6b2ac16b | 269 | |
davidmateos | 14:21cb6b2ac16b | 270 | if(y==1) { |
davidmateos | 11:ff1efbab2d9e | 271 | gOled.clearDisplay(); |
davidmateos | 14:21cb6b2ac16b | 272 | gOled.printf("Programa de taladro\n"); |
davidmateos | 14:21cb6b2ac16b | 273 | gOled.display(); |
davidmateos | 14:21cb6b2ac16b | 274 | } |
davidmateos | 11:ff1efbab2d9e | 275 | tiempo.reset(); |
davidmateos | 14:21cb6b2ac16b | 276 | |
davidmateos | 15:2acad1c57ad4 | 277 | //int error = 0; |
davidmateos | 10:db8ef252faba | 278 | pc.baud(115200); |
davidmateos | 14:21cb6b2ac16b | 279 | |
davidmateos | 15:2acad1c57ad4 | 280 | //if(ds1820.begin()) { |
davidmateos | 15:2acad1c57ad4 | 281 | //while(1) { |
davidmateos | 14:21cb6b2ac16b | 282 | |
davidmateos | 14:21cb6b2ac16b | 283 | |
davidmateos | 15:2acad1c57ad4 | 284 | // ds1820.startConversion(); // start temperature conversion from analog to digital |
davidmateos | 15:2acad1c57ad4 | 285 | // wait(1.0); // let DS1820 complete the temperature conversion |
davidmateos | 15:2acad1c57ad4 | 286 | // error = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) |
davidmateos | 15:2acad1c57ad4 | 287 | // switch(error) { |
davidmateos | 15:2acad1c57ad4 | 288 | // case 0: // no errors -> 'temp' contains the value of measured temperature |
davidmateos | 15:2acad1c57ad4 | 289 | // pc.printf("temp = %3.1f C\r\n", temp); |
davidmateos | 15:2acad1c57ad4 | 290 | // break; |
davidmateos | 15:2acad1c57ad4 | 291 | // case 1: // no sensor present -> 'temp' is not updated |
davidmateos | 15:2acad1c57ad4 | 292 | // pc.printf("no sensor present\n\r"); |
davidmateos | 15:2acad1c57ad4 | 293 | // break; |
davidmateos | 15:2acad1c57ad4 | 294 | // case 2: // CRC error -> 'temp' is not updated |
davidmateos | 15:2acad1c57ad4 | 295 | // pc.printf("CRC error\r\n"); |
davidmateos | 15:2acad1c57ad4 | 296 | // } |
davidmateos | 15:2acad1c57ad4 | 297 | // led = !led; |
davidmateos | 15:2acad1c57ad4 | 298 | // } |
davidmateos | 15:2acad1c57ad4 | 299 | // } else |
davidmateos | 15:2acad1c57ad4 | 300 | // pc.printf("No DS1820 sensor found!\r\n"); |
davidmateos | 14:21cb6b2ac16b | 301 | |
davidmateos | 14:21cb6b2ac16b | 302 | |
davidmateos | 14:21cb6b2ac16b | 303 | |
davidmateos | 15:2acad1c57ad4 | 304 | //if(x==1 || y==1){ |
davidmateos | 14:21cb6b2ac16b | 305 | |
javiervicente | 0:8a1a447db446 | 306 | while(1) { |
davidmateos | 15:2acad1c57ad4 | 307 | |
javiervicente | 0:8a1a447db446 | 308 | distancia=usensor.get_dist_cm(); |
davidmateos | 16:d49a029f2a1b | 309 | if (switcher ==0){ |
davidmateos | 16:d49a029f2a1b | 310 | y=0; |
davidmateos | 16:d49a029f2a1b | 311 | x=1; |
davidmateos | 16:d49a029f2a1b | 312 | }else if (switcher==1){ |
davidmateos | 16:d49a029f2a1b | 313 | y=1; |
davidmateos | 16:d49a029f2a1b | 314 | x=0; |
davidmateos | 16:d49a029f2a1b | 315 | } |
davidmateos | 15:2acad1c57ad4 | 316 | |
davidmateos | 15:2acad1c57ad4 | 317 | if (boton ==1){ |
davidmateos | 16:d49a029f2a1b | 318 | contador=0; |
davidmateos | 15:2acad1c57ad4 | 319 | } |
davidmateos | 15:2acad1c57ad4 | 320 | |
davidmateos | 11:ff1efbab2d9e | 321 | //calefactor |
davidmateos | 14:21cb6b2ac16b | 322 | // rele=1; |
davidmateos | 14:21cb6b2ac16b | 323 | // led=1; |
davidmateos | 11:ff1efbab2d9e | 324 | // wait(1.0); |
davidmateos | 14:21cb6b2ac16b | 325 | // rele=0; |
davidmateos | 11:ff1efbab2d9e | 326 | // led=0; |
davidmateos | 14:21cb6b2ac16b | 327 | // wait(1.0); |
davidmateos | 11:ff1efbab2d9e | 328 | // |
davidmateos | 15:2acad1c57ad4 | 329 | // if(ds1820.begin()) { |
davidmateos | 15:2acad1c57ad4 | 330 | // ds1820.startConversion(); // start temperature conversion from analog to digital |
davidmateos | 15:2acad1c57ad4 | 331 | // wait(1.0); // let DS1820 complete the temperature conversion |
davidmateos | 15:2acad1c57ad4 | 332 | // error = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) |
davidmateos | 15:2acad1c57ad4 | 333 | // switch(error) { |
davidmateos | 15:2acad1c57ad4 | 334 | // case 0: // no errors -> 'temp' contains the value of measured temperature |
davidmateos | 15:2acad1c57ad4 | 335 | // pc.printf("temp = %3.1f C\r\n", temp); |
davidmateos | 15:2acad1c57ad4 | 336 | // break; |
davidmateos | 15:2acad1c57ad4 | 337 | // case 1: // no sensor present -> 'temp' is not updated |
davidmateos | 15:2acad1c57ad4 | 338 | // pc.printf("no sensor present\n\r"); |
davidmateos | 15:2acad1c57ad4 | 339 | // break; |
davidmateos | 15:2acad1c57ad4 | 340 | // case 2: // CRC error -> 'temp' is not updated |
davidmateos | 15:2acad1c57ad4 | 341 | // pc.printf("CRC error\r\n"); |
davidmateos | 15:2acad1c57ad4 | 342 | // } |
davidmateos | 15:2acad1c57ad4 | 343 | // led = !led; |
davidmateos | 15:2acad1c57ad4 | 344 | // } |
davidmateos | 15:2acad1c57ad4 | 345 | // else |
davidmateos | 15:2acad1c57ad4 | 346 | // pc.printf("No DS1820 sensor found!\r\n"); |
davidmateos | 14:21cb6b2ac16b | 347 | |
javiervicente | 0:8a1a447db446 | 348 | switch ( estado ) { |
javiervicente | 0:8a1a447db446 | 349 | case cerrada: |
javiervicente | 0:8a1a447db446 | 350 | estadoCerrada(); |
javiervicente | 0:8a1a447db446 | 351 | break; |
javiervicente | 0:8a1a447db446 | 352 | case abriendose: |
javiervicente | 0:8a1a447db446 | 353 | estadoAbriendose(); |
javiervicente | 0:8a1a447db446 | 354 | break; |
javiervicente | 0:8a1a447db446 | 355 | case abierta: |
javiervicente | 0:8a1a447db446 | 356 | estadoAbierta(); |
javiervicente | 0:8a1a447db446 | 357 | break; |
javiervicente | 0:8a1a447db446 | 358 | case cerrandose: |
javiervicente | 0:8a1a447db446 | 359 | estadoCerrandose(); |
javiervicente | 0:8a1a447db446 | 360 | break; |
javiervicente | 0:8a1a447db446 | 361 | default: |
javiervicente | 0:8a1a447db446 | 362 | break; |
javiervicente | 0:8a1a447db446 | 363 | } |
davidmateos | 15:2acad1c57ad4 | 364 | |
davidmateos | 15:2acad1c57ad4 | 365 | |
javiervicente | 0:8a1a447db446 | 366 | } |
davidmateos | 15:2acad1c57ad4 | 367 | } |
davidmateos | 15:2acad1c57ad4 | 368 | //} |