I'm trying to adapt the following code to use pin 9 instead of pin 8 (see setup()) but so far I have come up short. is this easy? impossible?
I tried to include the entire sketch, but it was too long...
thanks!
void setup()
{
Serial.begin(57600);
DDRB = 0x2F;
DDRB &= ~(1<<DDB0);
PORTB &= ~(1<<PORTB0);
DDRD |= B11000000;
TCCR1A = B00000000;
TCCR1B = ( _BV(ICNC1) | _BV(CS11) | _BV(CS10) );
SET_INPUT_CAPTURE_RISING_EDGE();
TIMSK1 = ( _BV(ICIE1) | _BV(TOIE1) );
Serial.println("[OS V3 Sensor Capture/Decode]");
WEATHER_RESET();
}
void loop()
{
// weather packet ready to decode
if(weather_rx_state == RX_STATE_PACKET_RECEIVED)
{
// Shift bits right 1
for (int j = packet_bit_pointer/8+1; j > 0; j--)
{
packet[j] >>= 1;
if ((packet[j - 1] & 0x01) == 1)
packet[j] |= (1 << (7));
}
packet[0] >>= 1;
switch(packet[0])
{
case 0x5F: DecodeTemp(); break;
case 0x5B: DecodeUV(); break;
case 0x58: DecodeWind(); break;
case 0x54: DecodeRain(); break;
}
WEATHER_RESET();
}
}
// THGN801 Temperature / Humidity Sensor Data Format.
// Sample Data:
// 01011111000101000010100001000000100011001000000000001100101000001011010001111001
// --------------------------------4444333322221111SSSS66665555--------CCCC--------
//
// 11112222.33334444 = Temperature
// 55556666 = Humidity %
// CCCC = CRC
void DecodeTemp()
{
// check the packet CRC
if (!ValidCRC(16))
{
Serial.println("Temp: CRC Error!");
return;
}
// grab the temperature
int whole = (GetNibble(11) * 10) + GetNibble(10);
int decimal = (GetNibble(9) * 10) + GetNibble(8);
temprature = (decimal * 0.01) + whole;
if (GetNibble(12) == 1)
temprature *= -1;
// convert Celsius to Fahrenheit
temprature = ((9.0 / 5.0) * temprature) + 32;
// grab the humidity
humidity = (GetNibble(14) * 10) + GetNibble(13);
Serial.print("Temp: ");
Serial.print( temprature);
Serial.print(" Humidity: ");
Serial.println(humidity);
}
// UVN800 UV Sensor
// Sample Data:
// 010110110001111000101000101100100000000000001000111000000101110001110000
// ------------------------------------11111----------------CCCC-----------
//
// 1111 = UV
// CCCC = CRC
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.