first commit
This commit is contained in:
151
ATMEGA_SERIAL/ATMEGA_SERIAL.ino
Executable file
151
ATMEGA_SERIAL/ATMEGA_SERIAL.ino
Executable file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_BMP085.h>
|
||||
|
||||
#define LED_PIN (13)
|
||||
|
||||
//
|
||||
float temperature = 0.0;
|
||||
float pressure = 0.0;
|
||||
float pression = 0.0;
|
||||
float presiune = 0.0;
|
||||
int sensorValue = 0;
|
||||
int sensorValue2 = 0;
|
||||
int sensorValue3 = 0;
|
||||
int distance = 0;
|
||||
|
||||
//const int TrigPin = 2;
|
||||
//const int EchoPin = 3;
|
||||
|
||||
// ################# Barometre ####
|
||||
Adafruit_BMP085 bmp;
|
||||
// #####################
|
||||
|
||||
|
||||
// =============================================================
|
||||
/******************************************************************/
|
||||
void reSetup() {
|
||||
// pinMode(TrigPin, OUTPUT);
|
||||
// pinMode(EchoPin, INPUT);
|
||||
Serial.begin(115200);
|
||||
|
||||
// Sleep
|
||||
/* Don't forget to configure the pin! */
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
void setup() {
|
||||
|
||||
reSetup();
|
||||
|
||||
/*** Configure the timer.***/
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
barometre();
|
||||
|
||||
readSensors();
|
||||
|
||||
//readPresence();
|
||||
|
||||
sendAll();
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
delay(2000);
|
||||
|
||||
}
|
||||
void sendAll() {
|
||||
|
||||
sendValues("TEMPERATURE", temperature * 100);
|
||||
|
||||
sendValues("PRESSION", (int) (pression * 10));
|
||||
|
||||
sendValues("PRESSURE", (int) (pressure * 10));
|
||||
|
||||
sendValues("SENSOR_1", sensorValue);
|
||||
|
||||
sendValues("SENSOR_2", sensorValue2);
|
||||
|
||||
sendValues("SENSOR_3", (int) (sensorValue3 / 10.24));
|
||||
|
||||
//sendValues("DISTANCE", distance);
|
||||
|
||||
}
|
||||
|
||||
void barometre() {
|
||||
/* See Example: TypeA_WithDIPSwitches */
|
||||
// mySwitch.switchOn("00001", "10000");
|
||||
// delay(1000);
|
||||
// BMP
|
||||
if (bmp.begin()) {
|
||||
|
||||
temperature = bmp.readTemperature();
|
||||
pressure= bmp.readPressure() / 100.0;
|
||||
pression = pressure / 101.325;
|
||||
pression = pression * 0.760 * 100;
|
||||
// http://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea_level_pressure
|
||||
// Serial.print("Presiure la nivelul marii (calculata) = ");
|
||||
presiune = bmp.readSealevelPressure() / 101.325;
|
||||
presiune = presiune * 0.760;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//void readPresence() {
|
||||
// digitalWrite(TrigPin, LOW); //Low high and low level take a short time to TrigPin pulse
|
||||
// delayMicroseconds(2);
|
||||
// digitalWrite(TrigPin, HIGH);
|
||||
// delayMicroseconds(10);
|
||||
// digitalWrite(TrigPin, LOW);
|
||||
//
|
||||
// float cm = pulseIn(EchoPin, HIGH) / 58.0; //Echo time conversion into cm
|
||||
// cm = (int(cm * 100.0)) / 100.0; //Keep two decimal places
|
||||
//
|
||||
// distance = cm * 100;
|
||||
//
|
||||
//}
|
||||
|
||||
void readSensors() {
|
||||
// ##########################################"
|
||||
// Analogic read
|
||||
// ------------------------------------------
|
||||
sensorValue = analogRead(A0);
|
||||
sensorValue2 = analogRead(A1);
|
||||
sensorValue3 = analogRead(A2);
|
||||
// int sensorValue4 = digitalRead(10);
|
||||
|
||||
//vol = (float)sensorValue / 1024 * 5.0;
|
||||
|
||||
// ##########################################
|
||||
|
||||
|
||||
}
|
||||
|
||||
void sendValues(String id, int value) {
|
||||
|
||||
|
||||
Serial.print(id);
|
||||
Serial.print("=");
|
||||
Serial.println(value);
|
||||
// mySwitch.switchOn(buf,buf2);
|
||||
// mySwitch.switchOn(id, value);
|
||||
// delay(1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user