Pages: [1]   Go Down
Author Topic: Help with this please!!  (Read 1596 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have this code:
Code:
#include <OneWire.h>
#include <DallasTemperature.h>

//TODO: Investigate the ~ in beside the port number in the board (e.g., ~3 vs 4)

#define ONE_WIRE_BUS 4    //temperature on port 4

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DeviceAddress insideThermometer = { 0x28, 0x43, 0xC2, 0x03, 0x04, 0x00, 0x00, 0x85 };

volatile boolean r1IsEvent;
volatile boolean r2IsEvent;
volatile int pcounter;

int RELAY = 13;  //pin for the RELAY

void setup(void)
{
  Serial.begin(9600);
  
  sensors.begin();
  
  sensors.setResolution(insideThermometer, 10);
  r1IsEvent = false;
  r2IsEvent = false;
  pcounter =
  //attach receiver one to pin 2
  attachInterrupt(0, receiverOneChanged, FALLING);
  //attach receiver one to pin 3
  attachInterrupt(1, receiverTwoChanged, FALLING);
  
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop(void)
{
  delay(4000);
  Serial.print("Here we go!!!...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("The temperature is: \n\r");
  printTemperature(insideThermometer);
  Serial.print("\n\r");
  Serial.print("We got it!!!!\n\r");
  Serial.print("\n\r");
  Serial.print("\n\r");
  Serial.print("\n\r");
}


void receiveOneChanged(){
   r1IsEvent = true;
  if(r2IsEvent){
     r1IsEvent = false;
     r2IsEvent = false;
     //person exit
     pcounter = pcounter - 1;
     if(pcounter == 0){
       digitalWrite(RELAY, LOW);
     }    
  }
}

void receiveTwoChanged(){
  r2IsEvent = true;
  if(r1IsEvent){
     if(pcounter == 0){
       digitalWrite(RELAY, HIGH);
     }
     r1IsEvent = false;
     r2IsEvent = false;
     //person entered
     pcounter = pcounter + 1;    
  }
}

///////////////////////////
I need to fix this code. Ive been trying different resources but im not getting any help. Can someone help me?? If i need to pay for the help consider that im a student and not working. thanks

Moderator edit: Code (tags) fixed. No charge.
« Last Edit: October 17, 2012, 09:13:37 am by AWOL » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This compiles:

Code:
#include <OneWire.h>
#include <DallasTemperature.h>

//TODO: Investigate the ~ in beside the port number in the board (e.g., ~3 vs 4)

#define ONE_WIRE_BUS 4    //temperature on port 4

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DeviceAddress insideThermometer = { 0x28, 0x43, 0xC2, 0x03, 0x04, 0x00, 0x00, 0x85 };

volatile boolean r1IsEvent;
volatile boolean r2IsEvent;
volatile int pcounter;

int RELAY = 13;  //pin for the RELAY

void setup(void)
{
  Serial.begin(9600);
 
  sensors.begin();
 
  sensors.setResolution(insideThermometer, 10);
  r1IsEvent = false;
  r2IsEvent = false;
  pcounter = 0;
  //attach receiver one to pin 2
  attachInterrupt(0, receiverOneChanged, FALLING);
  //attach receiver one to pin 3
  attachInterrupt(1, receiverTwoChanged, FALLING);
 
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop(void)
{
  delay(4000);
  Serial.print("Here we go!!!...\n\r");
  sensors.requestTemperatures();
 
  Serial.print("The temperature is: \n\r");
  printTemperature(insideThermometer);
  Serial.print("\n\r");
  Serial.print("We got it!!!!\n\r");
  Serial.print("\n\r");
  Serial.print("\n\r");
  Serial.print("\n\r");
}


void receiverOneChanged(){
   r1IsEvent = true;
  if(r2IsEvent){
     r1IsEvent = false;
     r2IsEvent = false;
     //person exit
     pcounter = pcounter - 1;
     if(pcounter == 0){
       digitalWrite(RELAY, LOW);
     }  
  }
}

void receiverTwoChanged(){
  r2IsEvent = true;
  if(r1IsEvent){
     if(pcounter == 0){
       digitalWrite(RELAY, HIGH);
     }
     r1IsEvent = false;
     r2IsEvent = false;
     //person entered
     pcounter = pcounter + 1;  
  }
}

By the way, the ~ on pins denotes that they are PWM capable.
« Last Edit: October 17, 2012, 09:18:17 am by dxw00d » Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4085
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I need to fix this code. Ive been trying different resources but im not getting any help. Can someone help me?? If i need to pay for the help consider that im a student and not working. thanks

So what class is this code for?

Very difficult to help without understanding the problem, pay or not. If the code needs fixing, tell us what it is expected to do, and in what way it is broken.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If the code needs fixing, tell us what it is expected to do, and in what way it is broken.
OP did in another thread where he ignored me.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4085
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If the code needs fixing, tell us what it is expected to do, and in what way it is broken.
OP did in another thread where he ignored me.

Another cross-post eh
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Pages: [1]   Go Up
Jump to: