hey i have a problem with my code. I would like my display to switch after vibration. I have two separate programs that work, but as soon as I want to combine them, I can't, any advice?
first:
#include <Arduino.h>
#include <Wire.h>
//displej
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#define i2c_Address 0x3c
#define OLED_RESET -1
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//CO2
int CO2Pin = 14;
int CO2Puls = digitalPinToInterrupt(CO2Pin);
int koncentrace;
long HSTick=0, HETick=0;
long HHodnoty=0, LHodnoty=0;
byte a=0;
double HHodnoty_ms;
//BME280
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
int teplota;
int tlak;
int vlhkost;
void CO2Interrupt()
{
if (digitalRead(CO2Pin)) {
HSTick = micros(); // store the current micros() value
if(2 == a){
a = 4;
if(HSTick > HETick) {
LHodnoty = HSTick - HETick;
}
}else{
a = 1;
}
} else {
HETick = micros(); // store the current micros() value
if(1 == a){
a = 2;
if(HETick > HSTick){
HHodnoty = HETick - HSTick;
}
}
}
}
void Oxid()
{
if(a == 4){
a = 1;
HHodnoty_ms = (HHodnoty * 1000.0) / (LHodnoty + HHodnoty);
if (HHodnoty_ms < 0.01){
Serial.println("Chyba");
}
else if (HHodnoty_ms < 80.00){
Serial.println("zahrivani");
}
else if (HHodnoty_ms < 998.00){
koncentrace = (HHodnoty_ms - 2) * 5;
//Print CO2 koncentrace
Serial.print(koncentrace);
Serial.println("ppm");
}else{
Serial.println("Za hranici mereni : 398~4980ppm");
}
Serial.println();
}
}
void BME() {
teplota = bme.readTemperature();
tlak = bme.readPressure()/100;
vlhkost = bme.readHumidity();
if (vlhkost > 100) {
vlhkost = 100;
}
Serial.print(teplota);
Serial.println("C");
Serial.print(vlhkost);
Serial.println("%");
Serial.print(tlak);
Serial.println("hPa");
Serial.println();
}
void setup() {
Serial.begin(115200);
display.begin(i2c_Address, true);
display.display();
delay(2000);
display.clearDisplay();
pinMode(CO2Pin, INPUT);
attachInterrupt(CO2Puls, CO2Interrupt, CHANGE);
bme.begin();
}
void loop()
{
Oxid();
BME();
display.setTextSize(1);
display.clearDisplay();
display.setTextColor(SH110X_WHITE);
display.setCursor(11 , 8);
display.print("Teplota: ");
display.setCursor(66 , 8);
display.print(teplota);
display.print(" ");
display.print((char)247); // symbol stupně
display.println("C");
display.setCursor(11 , 24);
display.println("Tlak: ");
display.setCursor(66 , 24);
display.print(tlak);
display.print(" hPa");
display.setCursor(11 , 40);
display.println("Vlhkost: ");
display.setCursor(66 , 40);
display.print(vlhkost);
display.print(" %");
display.setCursor(11 , 56);
display.println("CO2: ");
display.setCursor(66 , 56);
if (HHodnoty_ms < 0.01){
display.println("Chyba");
}
else if (HHodnoty_ms < 80.00){
display.println("Zahrivani");
}
else if (HHodnoty_ms < 998.00){
display.print(koncentrace);
display.println("ppm");
}
else{
display.println("Za hranici mereni : 398~4980ppm");
}
display.display();
delay(1000);
}
Your "vib()" function in the second sketch can be wholly moved to the first sketch. Then, add the call "vib();" to the first sketch and run the first sketch. Tell us what happens? You will see errors, so show those, too.
Then write the detailed description in your native language and use google-translate
The grammar will not be brilliant and a few words might be odd.
But the much more detailed description still give so much more information that it will be much better to understand. And nice side-effect if you read the english translation your english will improve