Zmiana kompilacji - Wersja do druku +- Arduino Polska Forum (https://forum.arduinopolska.pl) +-- Dział: "Projekt Arduino Polska" (https://forum.arduinopolska.pl/dzial-projekt-arduino-polska) +--- Dział: Zarys "Projektu Arduino Polska" (https://forum.arduinopolska.pl/dzial-zarys-projektu-arduino-polska) +--- Wątek: Zmiana kompilacji (/watek-zmiana-kompilacji) |
Zmiana kompilacji - siambi - 07-12-2022 Witam, znalazłem taki szkic do obsługi termometrów ds18b20 z lcd, i czodzi mi oto żeby zmienić go tak aby wyświetlało np. pokoj , kuchnia itd. zamiast Czujnik 1...2...3. Czy ktoś by był tak miły i pomógł mi i przerobił szkic. Z góry dziękuję. // 03.02.2018 - Writen by Robiuri #include <LiquidCrystal.h> #include <OneWire.h> #include <DallasTemperature.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize the LCD and tell it which pins is // to be used for communicating #define ONE_WIRE_BUS 8 // Data wire is plugged into port 8 on the Arduino #define precision 9 // OneWire precision Dallas Sensor #define contrast 9 // Define the pin that controls the contrast of the screen #define bright 10 // Define the pin the controls the brightness of the screen #define rows 2 // Define the rows in display LCD #define columns 16 // Define the columns in display LCD int licznik = 0; // Counter of Dallas sensors // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. DeviceAddress t1, t2, t3, t4, t5, t6, t7, t8; // arrays to hold device addresses void setup(void) { lcd.begin(columns, rows); //Tell the LCD that it is a Columns x Rows LCD pinMode(contrast, OUTPUT); //set pin contrast to OUTPUT pinMode(bright, OUTPUT); //Set pin brightness to OUTPUT digitalWrite(bright, HIGH); //LOW and HIGH <- digitalWrite OR analogWrite value 0-255 240 analogWrite(contrast, 50); //LOW and HIGH <- digitalWrite OR analogWrite value 0-255 54 lcd.noCursor(); //Disable cursor on LCD lcd.clear(); //Clear Screen on LCD Serial.begin(9600); //Start serial port Serial.println("Dallas Temperature IC Control Library"); // Start up the library sensors.begin(); // locate devices on the bus 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"); // Search for devices on the bus and assign based on an index. Ideally, // you would do this to initially discover addresses on the bus and then // use those addresses and manually assign them (see above) once you know // the devices on your bus (and assuming they don't change). // if (!sensors.getAddress(t1, 0)) Serial.println("No Found Sensor 1"); if (!sensors.getAddress(t2, 1)) Serial.println("No Found Sensor 2"); if (!sensors.getAddress(t3, 2)) Serial.println("No Found Sensor 3"); if (!sensors.getAddress(t4, 3)) Serial.println("No Found Sensor 4"); if (!sensors.getAddress(t5, 4)) Serial.println("No Found Sensor 5"); if (!sensors.getAddress(t6, 5)) Serial.println("No Found Sensor 6"); if (!sensors.getAddress(t7, 6)) Serial.println("No Found Sensor 7"); if (!sensors.getAddress(t8, 7)) Serial.println("No Found Sensor 8"); // show the addresses we found on the bus for (int ilosc =0; ilosc < sensors.getDeviceCount(); ilosc++) { Serial.print("Sensor "); Serial.print(ilosc+1); Serial.print(" Address: "); if (ilosc == 0) { printAddress(t1); Serial.println(); } else if (ilosc == 1) { printAddress(t2); Serial.println(); } else if (ilosc == 2) { printAddress(t3); Serial.println(); } else if (ilosc == 3) { printAddress(t4); Serial.println(); } else if (ilosc == 4) { printAddress(t5); Serial.println(); } else if (ilosc == 5) { printAddress(t6); Serial.println(); } else if (ilosc == 6) { printAddress(t7); Serial.println(); } else if (ilosc == 7) { printAddress(t8); Serial.println(); } } // set the resolution to 9 bit per device sensors.setResolution(t1, precision); sensors.setResolution(t2, precision); sensors.setResolution(t3, precision); sensors.setResolution(t4, precision); sensors.setResolution(t5, precision); sensors.setResolution(t6, precision); sensors.setResolution(t7, precision); sensors.setResolution(t8, precision); for (int ilosc =0; ilosc < sensors.getDeviceCount(); ilosc++) { Serial.print("Sensor "); Serial.print(ilosc+1); Serial.print(" Resolution: "); if (ilosc == 0) { Serial.print(sensors.getResolution(t1), DEC); Serial.println(); } else if (ilosc == 1) { Serial.print(sensors.getResolution(t2), DEC); Serial.println(); } else if (ilosc == 2) { Serial.print(sensors.getResolution(t3), DEC); Serial.println(); } else if (ilosc == 3) { Serial.print(sensors.getResolution(t4), DEC); Serial.println(); } else if (ilosc == 4) { Serial.print(sensors.getResolution(t5), DEC); Serial.println(); } else if (ilosc == 5) { Serial.print(sensors.getResolution(t6), DEC); Serial.println(); } else if (ilosc == 6) { Serial.print(sensors.getResolution(t7), DEC); Serial.println(); } else if (ilosc == 7) { Serial.print(sensors.getResolution(t8), 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); } } // function to print the temperature for a device void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); Serial.print("Temp : "); Serial.print(tempC); Serial.print(" Celcius degres "); // Serial.print(" Temp F: "); // Serial.print(DallasTemperature::toFahrenheit(tempC)); } // function to print a device's resolution void printResolution(DeviceAddress deviceAddress) { // Serial.print("Resolution: "); // Serial.print(sensors.getResolution(deviceAddress)); // Serial.println(); } // main function to print information about a device void printData(DeviceAddress deviceAddress) { Serial.print("Device Address: "); printAddress(deviceAddress); Serial.print(" "); printTemperature(deviceAddress); Serial.println(); } /* Main function, calls the temperatures in a loop. */ void loop(void) { // call sensors.requestTemperatures() to issue a global temperature request to all devices on the bus Serial.print("Reading DATA..."); sensors.requestTemperatures(); Serial.println("DONE"); // print the device information for (int ilosc =0; ilosc < sensors.getDeviceCount(); ilosc++) { Serial.print("Sensor "); Serial.print(ilosc+1); Serial.print(" "); if (ilosc == 0) { printData(t1); } else if (ilosc == 1) { printData(t2); } else if (ilosc == 2) { printData(t3); } else if (ilosc == 3) { printData(t4); } else if (ilosc == 4) { printData(t5); } else if (ilosc == 5) { printData(t6); } else if (ilosc == 6) { printData(t7); } else if (ilosc == 7) { printData(t8); } } if (licznik == sensors.getDeviceCount()) { licznik = 0; // reset counter // lcd.clear(); // clear screen on LCD } lcd.setCursor(0,0); lcd.print(" Czujnik "); lcd.print(licznik+1); lcd.setCursor(0,1); lcd.print(" Temp: "); if (licznik == 0) { lcd.print(sensors.getTempC(t1)); lcd.write((char)223); lcd.print("C "); } else if (licznik == 1) { lcd.print(sensors.getTempC(t2)); lcd.write((char)223); lcd.print("C "); } else if (licznik == 2) { lcd.print(sensors.getTempC(t3)); lcd.write((char)223); lcd.print("C "); } else if (licznik == 3) { lcd.print(sensors.getTempC(t4)); lcd.write((char)223); lcd.print("C "); } else if (licznik == 4) { lcd.print(sensors.getTempC(t5)); lcd.write((char)223); lcd.print("C "); } else if (licznik == 5) { lcd.print(sensors.getTempC(t6)); lcd.write((char)223); lcd.print("C "); } else if (licznik == 6) { lcd.print(sensors.getTempC(t7)); lcd.write((char)223); lcd.print("C "); } else if (licznik == 7) { lcd.print(sensors.getTempC(t8)); lcd.write((char)223); lcd.print("C "); } Serial.print("Licznik="); Serial.println(licznik); delay(1000); licznik++ ; } RE: Zmiana kompilacji - kaczakat - 07-12-2022 Kurs Arduino znajdziesz tu: https://forbot.pl/blog//kurs-arduino-podstawy-programowania-spis-tresci-kursu-id5290 Zrób sobie tablicę napisów, tam gdzie jest wydruk numeru czujnika na LCD wstaw sobie napisy[licznik]. RE: Zmiana kompilacji - siambi - 10-12-2022 Dzięki |