Hej Gerd
Nu har jeg prøvet det jeg skrev men for den kendte meddelelse (a function-definition is not allowed here before '{' token) i line 120 og 130 men jeg kan bare se hvad der er galt jeg har nok set mig blind på et eller andet
Mvh Jonny
#include <OneWire.h>
#include <DallasTemperature.h>
#include <NewPing.h>
#include "TimerOne.h"
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 9
//HC-SR04
#define TRIGGER_PIN 7
#define ECHO_PIN 6
#define MAX_DISTANCE 100
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
//Hall_sensor
const int buttonPin = 3; // the pin that the pushbutton is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
//DS18B20
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress udeTemp, indeTemp, kedelTemp, returTemp, varmvandsTemp;
void setup(void)
{
Timer1.initialize(10000); // initialize timer1, and set a 10ms second period
Timer1.attachInterrupt(my_loop); // attaches my_loop() as a timer overflow interrupt
}
void my_loop()
{
// this is called every 10ms. Keep it as short as possible. Do not use delay() inside !!
//Hall sensor
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
buttonPushCounter++;
}
{
// start serial port
Serial.begin(9600);
// Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// report parasite power requirements
// Serial.print("Parasite power is: ");
// if (sensors.isParasitePowerMode()) Serial.println("ON");
// else Serial.println("OFF");
// method 1: by index
if (!sensors.getAddress(udeTemp, 1)) Serial.println("Unable to find address for Device 0");
if (!sensors.getAddress(indeTemp, 2)) Serial.println("Unable to find address for Device 2");
if (!sensors.getAddress(kedelTemp, 0)) Serial.println("Unable to find address for Device 0");
if (!sensors.getAddress(returTemp, 3)) Serial.println("Unable to find address for Device 3");
if (!sensors.getAddress(varmvandsTemp, 4)) Serial.println("Unable to find address for Device 4");
// set the resolution to 9 bit
sensors.setResolution(udeTemp, TEMPERATURE_PRECISION);
sensors.setResolution(indeTemp, TEMPERATURE_PRECISION);
sensors.setResolution(kedelTemp, TEMPERATURE_PRECISION);
sensors.setResolution(returTemp, TEMPERATURE_PRECISION);
sensors.setResolution(varmvandsTemp, TEMPERATURE_PRECISION);
Serial.print("Device 1 Resolution: ");
Serial.print(sensors.getResolution(udeTemp), DEC);
Serial.println();
Serial.print("Device 2 Resolution: ");
Serial.print(sensors.getResolution(indeTemp), DEC);
Serial.println();
Serial.print("Device 0 Resolution: ");
Serial.print(sensors.getResolution(kedelTemp), DEC);
Serial.println();
Serial.print("Device 3 Resolution: ");
Serial.print(sensors.getResolution(returTemp), DEC);
Serial.println();
Serial.print("Device 4 Resolution: ");
Serial.print(sensors.getResolution(varmvandsTemp), DEC);
Serial.println();
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
// zero pad the address if necessary
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
void loop(void)
{
sensors.requestTemperatures();
Serial.println();
Serial.println();
Serial.println(" ---------------------------------");
Serial.print(" GAMMELDAM: ");
Serial.println(" Stoker control v.1.0");
Serial.println(" Created by Jonny Rethmeier");
Serial.println(" ---------------------------------");
Serial.println();
Serial.println();
Serial.println();
Serial.print(" Udetemperatur-: ");
Serial.print(sensors.getTempC(udeTemp));
Serial.println(" C");
Serial.println();
Serial.println();
Serial.print(" Indetemperatur-: ");
Serial.print(sensors.getTempC(indeTemp));
Serial.println(" C");
Serial.println();
Serial.println();
Serial.print(" Kedeltemperatur-: ");
Serial.print(sensors.getTempC(kedelTemp));
Serial.println(" C");
Serial.println();
Serial.println();
Serial.print(" Returtemperatur-: ");
Serial.print(sensors.getTempC(returTemp));
Serial.println(" C");
Serial.println();
Serial.println();
Serial.print(" Varmvandstemperatur-: ");
Serial.print(sensors.getTempC(varmvandsTemp));
Serial.println(" C");
Serial.println();
Serial.println();
//HC-SR04
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print(" Beholdning i pilletank-: ");
Serial.print(100-uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
Serial.print("%");
Serial.println();
Serial.print(" (Minimum 15%)");
Serial.println();
//Hall sensor
// read the pushbutton input pin:
//buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
//if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
// if (buttonState == HIGH) {
buttonPushCounter++;
Serial.println();
Serial.print(" Omgang af Pillesnegl: ");
Serial.print(buttonPushCounter);
Serial.println();
Serial.print(" Pilleforbrug: ");
Serial.print(buttonPushCounter*(0.03));
Serial.print(" kg. ");
Serial.println();
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
delay(10000);
}