06-03-2020, 23:27
(Ten post był ostatnio modyfikowany: 06-03-2020, 23:34 przez Jarewa0606.)
Ja ci powiem dziwne że ci to ardunio przepuszcza... Odwołujesz się do funkcji zanim została zdefiniowana...
np linijka 107
a zdefiniowane w 140 linijce tak nie może być
Zobacz teraz
np linijka 107
a zdefiniowane w 140 linijce tak nie może być
Zobacz teraz
Kod:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define OLED_ADDR 0x3C //defince OLED addres. Default was 0x3D and i thik it was adafruit default. But from aliexpress has onother athres. To find I2C address use I2Scanncer
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define RAIN_SENSOR_OPEN 1000
#define RAIN_SENSOR_CLOSE 400
int rainSensorPin[] = {A0, A1, A2, A3, A6}; //rain sesnors pins
int rainSensorValue[] = {0, 0, 0, 0, 0}; //rain sensor values
#define VALVE_OPEN 1
#define VALVE_CLOSE 0
int valvePin[] = {2, 3, 4, 5, 6};
int valveState[] = {VALVE_CLOSE, VALVE_CLOSE, VALVE_CLOSE, VALVE_CLOSE, VALVE_CLOSE};
#define PUMP_PIN 7
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) { // Address OLED
Serial.println(F("SSD1306 allocation failed"));
}
for(int i = 0; i < 5; i++){
pinMode(valvePin[i], OUTPUT);
}
pinMode(PUMP_PIN, OUTPUT);
// Clear the buffer
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 32);
display.println("Auto Garden v 0.1.");
display.display();
delay(500);
}
void printTableOnLCD(){
//vertical lines for dashboard
display.drawLine(01, 01, 01, 31, SSD1306_WHITE);
display.drawLine(16, 01, 16, 31, SSD1306_WHITE);
display.drawLine(31, 01, 31, 31, SSD1306_WHITE);
display.drawLine(46, 01, 46, 31, SSD1306_WHITE);
display.drawLine(61, 01, 61, 31, SSD1306_WHITE);
display.drawLine(76, 01, 76, 31, SSD1306_WHITE);
display.drawLine(91, 01, 91, 31, SSD1306_WHITE);
//horizontal lines for dashboard
display.drawLine(01, 01, 91, 01, SSD1306_WHITE);
display.drawLine(01, 11, 91, 11, SSD1306_WHITE);
display.drawLine(01, 21, 91, 21, SSD1306_WHITE);
display.drawLine(01, 31, 91, 31, SSD1306_WHITE);
//draw water lvl symbol
display.setCursor(04, 13);
display.print("W");
//display.drawBitmap(02, 12, image_water, 5, 5, SSD1306_WHITE);
//draw valve symbol
display.setCursor(04, 23);
display.print("P");
//display.drawBitmap(02, 22, image_valve, 5, 5, SSD1306_WHITE);
//draw pupmp symbol
//display.drawBitmap(65, 1, image_pump, 21, 16, SSD1306_WHITE);
}
void fillTableByData(){
Serial.print("In fillTableByData ");
for(int i = 0; i < 5; i++){
Serial.print(rainSensorValue[i]);
Serial.print(" ");
/*
display.setCursor(18 + 15 * i, 13);
display.print(rainSensorValue[i]/10, DEC);
display.setCursor(18 + 15 * i, 23);
display.print(valveState[i] == VALVE_OPEN ? 1 : 0, DEC);
*/
// display.drawBitmap(12 + 10 * i, 22, valveState[i] == VALVE_OPEN ? image_on : image_off, 5, 5, SSD1306_WHITE);
}
Serial.println();
}
void valveChangeState(int pin, int state){
valveState[pin] = state;
digitalWrite(pin, state == 1 ? HIGH : LOW);
}
void turnOnPump(){
Serial.println("Pump switch on");
digitalWrite(PUMP_PIN, HIGH);
}
void turnOffPump(){
Serial.println("Pump switch off");
digitalWrite(PUMP_PIN, LOW);
}
void openValve(int pin){
valveChangeState(pin, VALVE_OPEN);
}
void closeValve(int pin){
valveChangeState(pin, VALVE_CLOSE);
}
void loop() {
bool isAnyOpenedValve = false;
Serial.print("In messure loop values: ");
for(int i = 0; i < 5; i++){
rainSensorValue[i] = analogRead(rainSensorPin[i]); //read value of 'i' sensor
Serial.print(rainSensorValue[i]);
Serial.print(" ");
if(rainSensorValue[i] >= RAIN_SENSOR_OPEN){ //if value greater or equal open valve thrshole
openValve(valvePin[i]); //open valve and save them state
isAnyOpenedValve = true; //indicate that valve is opened
}
if(rainSensorValue[i] <= RAIN_SENSOR_CLOSE){
closeValve(valvePin[i]);
}
}
Serial.println();
if(isAnyOpenedValve){ //let's check if is any valve opened
turnOnPump(); //if so then powe up pump! even if was switched on
}else{
turnOffPump(); //if no thet power off pump, even if was switched off
}
display.clearDisplay();
//printTableOnLCD();
fillTableByData();
display.display(); // Show initial text
delay(5000);
}
Arduino zostało wymyślone po to, by robić dobrze jedną prostą rzecz – migać diodą.