temp sensor over 433Mhz

Dependencies:   FastIO

BBC MicroBit with RF 433Mhz receiver reading Oregon-Scientific wireless temperature sensor. Originally written for the Raspberry Pi but easily converted for the little microbit.

Committer:
daw9000
Date:
Tue Jul 26 13:42:32 2016 +0000
Revision:
1:706c7b028278
Parent:
0:13cb9cc98bca
Child:
2:7455dae4e624
V1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daw9000 0:13cb9cc98bca 1 /* Program Oregon Written by David Wright, Jan 2015. */
daw9000 0:13cb9cc98bca 2 /* thanks and plagarised from various internet sources on oregon sensors. Paul(DISK91.com), ALTelectronics for their document on */
daw9000 0:13cb9cc98bca 3 /* Oregon Scientific RF protocol v1.0, kevinmehall on github for rtldr-433m-sensor, Alexander Yerezeyev and more .... */
daw9000 0:13cb9cc98bca 4 /* */
daw9000 0:13cb9cc98bca 5 /* This Program reads a 433Mhz transmission from an Oregon version 1 Protocol Temperature Sensor */
daw9000 0:13cb9cc98bca 6 /* */
daw9000 0:13cb9cc98bca 7 /* Programming uses the logic of first detecting the preamble portion of transmission by counting the number of short 1 pulses */
daw9000 0:13cb9cc98bca 8 /* Next the progam monitors the 3 sync pulses and translates the last sync pulse to determine the first data message bit either 1 or 0 */
daw9000 0:13cb9cc98bca 9 /* From knowing the first message data bit the program determines the next 31 message data bits using the logic as follows:- */
daw9000 0:13cb9cc98bca 10 /* Two SHORT pulses means that the message data bit is the same as the previous message data bit (we know first so can do this) */
daw9000 0:13cb9cc98bca 11 /* One LONG pulse means that the message data bit is opposite (inverse) of the previous message data bit. */
daw9000 0:13cb9cc98bca 12 /* */
daw9000 0:13cb9cc98bca 13 /* The resulting 32 bit message is reversed to form 8 nibbles(4 bit). These nibbles are decoded to produce the data values. */
daw9000 0:13cb9cc98bca 14 /* */
daw9000 0:13cb9cc98bca 15 /* This program is quite basic and simplistic in that there is no error checking and only really gets temperature, channel and low bat */
daw9000 0:13cb9cc98bca 16 /* I wrote this program to learn C programming from being a visual basic and java programmer and as an aid to learning to code */
daw9000 0:13cb9cc98bca 17 /* hardware interfaces on my Raspberry Pi B+. I found plenty of code for various Oregon sensors but none I could easily understand */
daw9000 0:13cb9cc98bca 18 /* from the C or Python code. Hence this program does nothing clever using bitwise or memory facilities or uses no rising clock edges */
daw9000 0:13cb9cc98bca 19 /* , falling clock edges, clock ticks etc. Just simple time measurement and ONs and OFFs. Also I dont do any hex conversions. */
daw9000 0:13cb9cc98bca 20 /* There are no hex conversions because for channel, temperature and low battery all the hex and decimal values are the same i.e. */
daw9000 0:13cb9cc98bca 21 /* only numbers 0 to 9 are used for each part of the message. The temp minus sign and low battery are determined from the raw binary */
daw9000 0:13cb9cc98bca 22 /* in nibble 2 (third nibble as it starts nibble zero). */
daw9000 0:13cb9cc98bca 23 /* */
daw9000 0:13cb9cc98bca 24 /* If you wish this program can be improved on by adding error checking by using the checksum (hex conversion needed) and/or */
daw9000 0:13cb9cc98bca 25 /* by storing values and checking against the second transmission of the same message (all messages sent twice, I sleep through the */
daw9000 0:13cb9cc98bca 26 /* second transmission Zzzzz). */
daw9000 0:13cb9cc98bca 27
daw9000 1:706c7b028278 28
daw9000 0:13cb9cc98bca 29 #include "MicroBit.h"
daw9000 1:706c7b028278 30 #include "FastIO.h"
daw9000 1:706c7b028278 31
daw9000 0:13cb9cc98bca 32 int thisPin;
daw9000 0:13cb9cc98bca 33 int lastPin;
daw9000 0:13cb9cc98bca 34 int preambleON;
daw9000 0:13cb9cc98bca 35 int onShortLo;
daw9000 0:13cb9cc98bca 36 int onShortHi;
daw9000 0:13cb9cc98bca 37 int offShortLo;
daw9000 0:13cb9cc98bca 38 int offShortHi;
daw9000 0:13cb9cc98bca 39 int onLongLo;
daw9000 0:13cb9cc98bca 40 int onLongHi;
daw9000 0:13cb9cc98bca 41 int offLongLo;
daw9000 0:13cb9cc98bca 42 int offLongHi;
daw9000 0:13cb9cc98bca 43 int syncEnd0Lo;
daw9000 0:13cb9cc98bca 44 int syncEnd0Hi;
daw9000 0:13cb9cc98bca 45 long timeDiff;
daw9000 0:13cb9cc98bca 46 long startedAt;
daw9000 0:13cb9cc98bca 47 long endedAt;
daw9000 0:13cb9cc98bca 48 int preambleFound;
daw9000 0:13cb9cc98bca 49 int dataBits[32];
daw9000 1:706c7b028278 50 //int myPin = 1; // MicroBit P1
daw9000 1:706c7b028278 51 MicroBitPin P1(MICROBIT_ID_IO_P1, MICROBIT_PIN_P1, PIN_CAPABILITY_ALL);
daw9000 0:13cb9cc98bca 52 MicroBit uBit;
daw9000 1:706c7b028278 53 FastInOut<MICROBIT_PIN_P1> (myPin);
daw9000 1:706c7b028278 54 Timer xTime;
daw9000 0:13cb9cc98bca 55 long getTime(long returnUsecs)
daw9000 0:13cb9cc98bca 56 {
daw9000 1:706c7b028278 57 returnUsecs = xTime.read_us();
daw9000 1:706c7b028278 58 /* struct timespec currentTime;
daw9000 0:13cb9cc98bca 59 long microSecs;
daw9000 0:13cb9cc98bca 60 long secs;
daw9000 1:706c7b028278 61 clock_gettime(CLOCK_MONOTONIC, &currentTime);
daw9000 0:13cb9cc98bca 62 microSecs = currentTime.tv_nsec * 0.001;
daw9000 0:13cb9cc98bca 63 secs = currentTime.tv_sec;
daw9000 0:13cb9cc98bca 64 returnUsecs = microSecs + secs * 1000; */
daw9000 1:706c7b028278 65
daw9000 1:706c7b028278 66 return(returnUsecs);
daw9000 0:13cb9cc98bca 67 }
daw9000 0:13cb9cc98bca 68 int getPinValue(int returnPinValue)
daw9000 0:13cb9cc98bca 69 {
daw9000 0:13cb9cc98bca 70 // returnPinValue = digitalRead(myPin);
daw9000 1:706c7b028278 71 returnPinValue = myPin.read();
daw9000 1:706c7b028278 72 return(returnPinValue);
daw9000 0:13cb9cc98bca 73 }
daw9000 0:13cb9cc98bca 74 int detectPreamble(int returnDetected)
daw9000 0:13cb9cc98bca 75 {
daw9000 1:706c7b028278 76
daw9000 1:706c7b028278 77 thisPin = getPinValue(thisPin);
daw9000 1:706c7b028278 78 if (!(thisPin == lastPin))
daw9000 1:706c7b028278 79 {
daw9000 1:706c7b028278 80 endedAt = getTime(endedAt); // set timer end for last pin
daw9000 1:706c7b028278 81 timeDiff = endedAt - startedAt; // reset time
daw9000 1:706c7b028278 82 if (lastPin == 1)
daw9000 1:706c7b028278 83 {
daw9000 1:706c7b028278 84 if ((timeDiff >= onShortLo) && (timeDiff <= onShortHi)) // error of margin on pulse length
daw9000 1:706c7b028278 85 {
daw9000 1:706c7b028278 86 preambleON++; // looking for 12 short ON pulses.
daw9000 1:706c7b028278 87 }
daw9000 1:706c7b028278 88 else // not preamble
daw9000 1:706c7b028278 89 {
daw9000 1:706c7b028278 90 preambleON = 0;
daw9000 1:706c7b028278 91 }
daw9000 1:706c7b028278 92 }
daw9000 1:706c7b028278 93 else // check is this preamble, lastPin off
daw9000 1:706c7b028278 94 {
daw9000 1:706c7b028278 95
daw9000 1:706c7b028278 96
daw9000 1:706c7b028278 97 if (preambleON < 11) // last preamble is special as next low not short(thisPin)
daw9000 1:706c7b028278 98 {
daw9000 1:706c7b028278 99 if ((timeDiff > offShortLo) && (timeDiff < offShortHi)) // off ok
daw9000 1:706c7b028278 100 {
daw9000 1:706c7b028278 101 }
daw9000 1:706c7b028278 102 else // not preamble
daw9000 1:706c7b028278 103 {
daw9000 1:706c7b028278 104 preambleON = 0;
daw9000 1:706c7b028278 105 }
daw9000 1:706c7b028278 106
daw9000 1:706c7b028278 107 }
daw9000 1:706c7b028278 108 }
daw9000 1:706c7b028278 109
daw9000 1:706c7b028278 110 startedAt = endedAt; // set timer start for this pin
daw9000 1:706c7b028278 111 lastPin = thisPin;
daw9000 1:706c7b028278 112 }
daw9000 1:706c7b028278 113 if (preambleON == 12)
daw9000 1:706c7b028278 114 {
daw9000 1:706c7b028278 115 returnDetected = 1;
daw9000 1:706c7b028278 116 }
daw9000 1:706c7b028278 117 else
daw9000 1:706c7b028278 118 {
daw9000 1:706c7b028278 119 returnDetected = 0;
daw9000 1:706c7b028278 120 }
daw9000 1:706c7b028278 121 return(returnDetected);
daw9000 0:13cb9cc98bca 122 }
daw9000 0:13cb9cc98bca 123 int getSync()
daw9000 0:13cb9cc98bca 124 {
daw9000 0:13cb9cc98bca 125 // sync is long OFF, long ON, long OFF
daw9000 1:706c7b028278 126
daw9000 0:13cb9cc98bca 127 int sCount;
daw9000 1:706c7b028278 128 sCount = 1;
daw9000 0:13cb9cc98bca 129 thisPin = getPinValue(thisPin);
daw9000 0:13cb9cc98bca 130 lastPin = thisPin; //looking for state changes
daw9000 0:13cb9cc98bca 131 while (sCount < 3) // 3 sync pulses
daw9000 0:13cb9cc98bca 132 {
daw9000 0:13cb9cc98bca 133 if (!(thisPin == lastPin))
daw9000 0:13cb9cc98bca 134 {
daw9000 1:706c7b028278 135 sCount ++;
daw9000 1:706c7b028278 136 if (sCount == 3)
daw9000 1:706c7b028278 137 {
daw9000 1:706c7b028278 138 startedAt = getTime(startedAt); // time this pulse to get first bit value
daw9000 1:706c7b028278 139 }
daw9000 1:706c7b028278 140 lastPin = thisPin;
daw9000 0:13cb9cc98bca 141 }
daw9000 0:13cb9cc98bca 142 thisPin = getPinValue(thisPin); // poll the pin state
daw9000 0:13cb9cc98bca 143 }
daw9000 0:13cb9cc98bca 144 while ((thisPin == lastPin))
daw9000 0:13cb9cc98bca 145 {
daw9000 0:13cb9cc98bca 146 thisPin = getPinValue(thisPin);
daw9000 0:13cb9cc98bca 147 }
daw9000 0:13cb9cc98bca 148 endedAt = getTime(endedAt);
daw9000 1:706c7b028278 149 timeDiff = endedAt - startedAt;
daw9000 1:706c7b028278 150 startedAt = endedAt; // start timer for next bit.
daw9000 1:706c7b028278 151 if (timeDiff > syncEnd0Lo && timeDiff < syncEnd0Hi)
daw9000 1:706c7b028278 152 {
daw9000 1:706c7b028278 153 dataBits[0] = 0;
daw9000 1:706c7b028278 154 }
daw9000 1:706c7b028278 155 else
daw9000 1:706c7b028278 156 {
daw9000 1:706c7b028278 157 dataBits[0] = 1;
daw9000 1:706c7b028278 158 }
daw9000 0:13cb9cc98bca 159 return;
daw9000 0:13cb9cc98bca 160 }
daw9000 1:706c7b028278 161
daw9000 0:13cb9cc98bca 162 int getData()
daw9000 0:13cb9cc98bca 163 {
daw9000 0:13cb9cc98bca 164 // get next 31 data bits, we determined bit 0 in SYNC
daw9000 0:13cb9cc98bca 165 int i;
daw9000 0:13cb9cc98bca 166 int l;
daw9000 0:13cb9cc98bca 167 int s;
daw9000 0:13cb9cc98bca 168 i = 1; //first bit[0] was derived in Sync
daw9000 1:706c7b028278 169 s = 0; // short pulse
daw9000 1:706c7b028278 170 l = 0; // long pulse
daw9000 1:706c7b028278 171
daw9000 0:13cb9cc98bca 172 while (i < 32)
daw9000 0:13cb9cc98bca 173 {
daw9000 0:13cb9cc98bca 174 if (!(thisPin == lastPin)) // lastPin and thisPin are from getSync.
daw9000 0:13cb9cc98bca 175 {
daw9000 0:13cb9cc98bca 176 endedAt = getTime(endedAt); // timer started in getSync
daw9000 0:13cb9cc98bca 177 timeDiff = endedAt - startedAt;
daw9000 1:706c7b028278 178 startedAt = endedAt; // next starts at this end
daw9000 1:706c7b028278 179 if (lastPin == 0) //lastPin was OFF
daw9000 1:706c7b028278 180 {
daw9000 1:706c7b028278 181 if ((timeDiff > offShortLo) && (timeDiff < offShortHi))
daw9000 1:706c7b028278 182 { // short off detected
daw9000 1:706c7b028278 183 s++;
daw9000 1:706c7b028278 184 l=0;
daw9000 1:706c7b028278 185 }
daw9000 1:706c7b028278 186 if ((timeDiff > offLongLo) && (timeDiff < offLongHi))
daw9000 1:706c7b028278 187 { // long off detected
daw9000 1:706c7b028278 188 l++;
daw9000 1:706c7b028278 189 s=0;
daw9000 1:706c7b028278 190 }
daw9000 1:706c7b028278 191 }
daw9000 1:706c7b028278 192 else // lastPin was ON
daw9000 1:706c7b028278 193 {
daw9000 1:706c7b028278 194 if ((timeDiff > onShortLo) && (timeDiff < onShortHi)) // half-time
daw9000 1:706c7b028278 195 { // short on detetcted
daw9000 1:706c7b028278 196 s++;
daw9000 1:706c7b028278 197 l=0;
daw9000 1:706c7b028278 198 }
daw9000 1:706c7b028278 199 if ((timeDiff > onLongLo) && (timeDiff < onLongHi)) // full-time
daw9000 1:706c7b028278 200 { // long on detected
daw9000 1:706c7b028278 201 l++;
daw9000 1:706c7b028278 202 s=0;
daw9000 1:706c7b028278 203 }
daw9000 1:706c7b028278 204 }
daw9000 1:706c7b028278 205 if (s == 2)
daw9000 1:706c7b028278 206 { // 2 short pulses this bit equals previous bit (we know 1st bit from sync)
daw9000 1:706c7b028278 207 dataBits[i] = dataBits[(i-1)];
daw9000 1:706c7b028278 208 i++;
daw9000 1:706c7b028278 209 s=0;
daw9000 1:706c7b028278 210 l=0;
daw9000 1:706c7b028278 211 }
daw9000 1:706c7b028278 212 if (l == 1)
daw9000 1:706c7b028278 213 { // 1 long pulse this bit is inverse of previous bit (we know 1st bit from sync)
daw9000 1:706c7b028278 214 if (dataBits[(i-1)] == 0)
daw9000 1:706c7b028278 215 {
daw9000 1:706c7b028278 216 dataBits[i] = 1;
daw9000 1:706c7b028278 217 }
daw9000 1:706c7b028278 218 else
daw9000 1:706c7b028278 219 {
daw9000 1:706c7b028278 220 dataBits[i] = 0;
daw9000 1:706c7b028278 221 }
daw9000 1:706c7b028278 222 l=0;
daw9000 1:706c7b028278 223 s=0;
daw9000 1:706c7b028278 224 i++;
daw9000 1:706c7b028278 225 }
daw9000 0:13cb9cc98bca 226 // update last pin to this pin value
daw9000 0:13cb9cc98bca 227 lastPin = thisPin;
daw9000 0:13cb9cc98bca 228 }
daw9000 0:13cb9cc98bca 229 thisPin = getPinValue(thisPin); // get pin value
daw9000 0:13cb9cc98bca 230 }
daw9000 1:706c7b028278 231 return;
daw9000 0:13cb9cc98bca 232 }
daw9000 1:706c7b028278 233
daw9000 0:13cb9cc98bca 234 int processData()
daw9000 0:13cb9cc98bca 235 {
daw9000 0:13cb9cc98bca 236 int x = 0;
daw9000 0:13cb9cc98bca 237 int y = 0;
daw9000 0:13cb9cc98bca 238 int z= 0;
daw9000 0:13cb9cc98bca 239 int nStart;
daw9000 0:13cb9cc98bca 240 int nFinish;
daw9000 0:13cb9cc98bca 241 int nibbleValue;
daw9000 0:13cb9cc98bca 242 int nibbleValues[8];
daw9000 0:13cb9cc98bca 243 int temp;
daw9000 0:13cb9cc98bca 244 int nib;
daw9000 0:13cb9cc98bca 245 int nibble[4];
daw9000 0:13cb9cc98bca 246 int lowBat=0;
daw9000 1:706c7b028278 247
daw9000 1:706c7b028278 248 for (x=0;x<8;x++)
daw9000 1:706c7b028278 249 {
daw9000 1:706c7b028278 250 for (y=0;y<4;y++){nibble[y]=0;} //initialise
daw9000 1:706c7b028278 251 nStart=(31-((x*4)+3)); // array index for nibble start
daw9000 1:706c7b028278 252 nFinish=nStart+4;
daw9000 1:706c7b028278 253 y = 3; // nibble index
daw9000 1:706c7b028278 254 // Reverse the bits in message data (dataBits) to create 8 nibbles of 4 bits.
daw9000 1:706c7b028278 255 for (z=nStart;z<nFinish;z++) // read 4 bits
daw9000 1:706c7b028278 256 {
daw9000 1:706c7b028278 257 if (y >= 0)
daw9000 1:706c7b028278 258 {
daw9000 1:706c7b028278 259 nibble[y]=dataBits[z];//reverse bits, y starts at 3 back to 0
daw9000 1:706c7b028278 260 y--;
daw9000 1:706c7b028278 261 }
daw9000 1:706c7b028278 262 }
daw9000 1:706c7b028278 263 nibbleValue=0;
daw9000 1:706c7b028278 264 nib=8;
daw9000 1:706c7b028278 265 temp=0;
daw9000 1:706c7b028278 266 for (z=0;z<4;z++) // convert this nibble to decimal from binary
daw9000 1:706c7b028278 267 {
daw9000 1:706c7b028278 268 temp=nibbleValue;
daw9000 1:706c7b028278 269 nibbleValue=(nib * nibble[z]) + temp;
daw9000 1:706c7b028278 270 temp=nib;
daw9000 1:706c7b028278 271 if (temp > 1) nib = (temp / 2);
daw9000 1:706c7b028278 272
daw9000 1:706c7b028278 273 }
daw9000 1:706c7b028278 274 nibbleValues[x] = nibbleValue; // store nibble decimal values
daw9000 1:706c7b028278 275 }
daw9000 1:706c7b028278 276
daw9000 1:706c7b028278 277 // Print out the converted decimal nibble values
daw9000 1:706c7b028278 278 for (x=0;x<8;x++)
daw9000 1:706c7b028278 279 {
daw9000 1:706c7b028278 280 if (x==6) //channel number conversion
daw9000 1:706c7b028278 281 {
daw9000 1:706c7b028278 282 temp=99;
daw9000 1:706c7b028278 283 if (nibbleValues[x]==0) temp=1;
daw9000 1:706c7b028278 284 if (nibbleValues[x]==4) temp=2;
daw9000 1:706c7b028278 285 if (nibbleValues[x]==8) temp=3;
daw9000 1:706c7b028278 286 // printf(" Channel : %d\n",temp);
daw9000 1:706c7b028278 287 uBit.display.scroll("Channel:");
daw9000 1:706c7b028278 288 uBit.display.scroll(temp);
daw9000 1:706c7b028278 289 }
daw9000 1:706c7b028278 290 if (x==2)
daw9000 1:706c7b028278 291 {
daw9000 1:706c7b028278 292 // printf(" Temperature:");
daw9000 1:706c7b028278 293 uBit.display.scroll("Temp :");
daw9000 1:706c7b028278 294 if ((nibbleValues[x]==10) || (nibbleValues[x]==2)) uBit.display.scroll("-"); // printf("-"); // 8 = low bat, 2=minus, 10=minus+low bat
daw9000 1:706c7b028278 295 if ((nibbleValues[x]==8) || (nibbleValues[x]==10)) lowBat=1; else lowBat=0;
daw9000 1:706c7b028278 296
daw9000 1:706c7b028278 297 }
daw9000 1:706c7b028278 298 if ((x==3) || (x==4)) uBit.display.scroll(nibbleValues[x]);// printf("%d",nibbleValues[x]);
daw9000 1:706c7b028278 299 if (x==5)
daw9000 1:706c7b028278 300 {
daw9000 1:706c7b028278 301 // printf(".");
daw9000 1:706c7b028278 302 // printf("%d degC.\n",nibbleValues[x]);
daw9000 1:706c7b028278 303 uBit.display.scroll(".");
daw9000 1:706c7b028278 304 uBit.display.scroll(nibbleValues[x]);
daw9000 1:706c7b028278 305 uBit.display.scroll("degC");
daw9000 1:706c7b028278 306
daw9000 1:706c7b028278 307 }
daw9000 1:706c7b028278 308 if (lowBat==1) uBit.display.scroll("Low Battery"); // printf("Low Battery. \n");
daw9000 1:706c7b028278 309 }
daw9000 1:706c7b028278 310 return;
daw9000 0:13cb9cc98bca 311 }
daw9000 0:13cb9cc98bca 312 int main()
daw9000 0:13cb9cc98bca 313 {
daw9000 0:13cb9cc98bca 314 int p;
daw9000 0:13cb9cc98bca 315 uBit.init();
daw9000 0:13cb9cc98bca 316 // on short 1720, on long 3180, off short 1219, off long 2680
daw9000 0:13cb9cc98bca 317 // sync 1 off 4200, sync 2 on 5700, sync 3 off 5200 (sync 3 off long 6680)
daw9000 0:13cb9cc98bca 318 onShortLo = 1500;
daw9000 0:13cb9cc98bca 319 onShortHi = 2400;
daw9000 0:13cb9cc98bca 320 offShortLo = 970;
daw9000 0:13cb9cc98bca 321 offShortHi = 1950;
daw9000 0:13cb9cc98bca 322 onLongLo = 2980;
daw9000 0:13cb9cc98bca 323 onLongHi = 3880;
daw9000 0:13cb9cc98bca 324 offLongLo = 1950;
daw9000 0:13cb9cc98bca 325 offLongHi = 2900;
daw9000 0:13cb9cc98bca 326 // syncBeginLo = 4000;
daw9000 0:13cb9cc98bca 327 // syncBeginHi = 4400;
daw9000 0:13cb9cc98bca 328 // syncLo = 5500;
daw9000 0:13cb9cc98bca 329 // syncHi = 5900;
daw9000 0:13cb9cc98bca 330 // syncEnd1Lo = 5000;
daw9000 0:13cb9cc98bca 331 // syncEnd1Hi = 5400;
daw9000 0:13cb9cc98bca 332 syncEnd0Lo = 6480;
daw9000 0:13cb9cc98bca 333 syncEnd0Hi = 6880;
daw9000 0:13cb9cc98bca 334 // wiringPiSetup();
daw9000 0:13cb9cc98bca 335 // pinMode(myPin, INPUT);
daw9000 0:13cb9cc98bca 336 uBit.io.pin[myPin].setDigitalValue(0);
daw9000 1:706c7b028278 337 preambleFound = 0;
daw9000 1:706c7b028278 338 preambleON = 0;
daw9000 1:706c7b028278 339 // printf("Waiting for transmission (approx. every 30s).\n");
daw9000 1:706c7b028278 340 // printf("Press Ctrl-C to exit.\n");
daw9000 1:706c7b028278 341 uBit.display.scroll("Waiting...");
daw9000 1:706c7b028278 342 while (1)
daw9000 1:706c7b028278 343 { // loop forever or ctrl-c
daw9000 1:706c7b028278 344
daw9000 1:706c7b028278 345 thisPin = getPinValue(thisPin);
daw9000 1:706c7b028278 346 lastPin = thisPin;
daw9000 1:706c7b028278 347 xTime.start();
daw9000 1:706c7b028278 348 endedAt = getTime(endedAt); // set initial timer end
daw9000 1:706c7b028278 349 startedAt = endedAt;
daw9000 1:706c7b028278 350
daw9000 1:706c7b028278 351 while (preambleFound == 0) // constantly monitor for preamble
daw9000 1:706c7b028278 352 {
daw9000 1:706c7b028278 353 preambleFound = detectPreamble(preambleFound);
daw9000 1:706c7b028278 354 }
daw9000 1:706c7b028278 355 if (preambleFound == 1)
daw9000 1:706c7b028278 356 {
daw9000 1:706c7b028278 357 getSync();
daw9000 1:706c7b028278 358 getData();
daw9000 1:706c7b028278 359 processData();
daw9000 1:706c7b028278 360 preambleFound = 0;
daw9000 1:706c7b028278 361 preambleON = 0;
daw9000 1:706c7b028278 362 uBit.sleep(10); // avoid second xmission of same data
daw9000 1:706c7b028278 363 }
daw9000 1:706c7b028278 364 }
daw9000 1:706c7b028278 365 exit(0);
daw9000 1:706c7b028278 366 }