Close

Odpověď na: Max6675

Úvodní stránka Fórum Vaše projekty Arduino Max6675 Odpověď na: Max6675

#10442
rehot79
Účastník

Som tu znova s novými úpravami kódu kde pribudol oled Display. Este raz podotykam ze toto je môj prvý projekt. Ak vydite nejake chyby tak kľudne do mňa . Zatiaľ to funguje.


//M.jakab29@gmail.com

//Vsetky kniznice nacitane v arduinoIDE spravca kniznic ///// 
#include "max6675.h"
//Servo
#include <Servo.h>
Servo myservo;
//Oled ///////////////////
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
/////////////

//Definicia pin

int thermoSO = 6;   
int thermoCS = 5;   
int thermoSCK = 4;  
MAX6675 thermocouple(thermoSCK, thermoCS, thermoSO);
int vccPin = 3; //Napajanie + pre max6675 modul z digitalneho pinu
int gndPin = 2; //Napajanie - pre max6675 modul z digitalneho pinu
int val;
int poloha;  
void setup() {
  
  
  // definicia napajacich pinou 
  pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
  pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);   
  ////definicia servo pinu
  myservo.attach(9);
 
  //////////////////////Oled////////////
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  // init done
  
  
  // Vycisti logo
  display.clearDisplay();
}
void loop() {
// basic readout test, just print the current temp
  
   val = thermocouple.readCelsius()-2;
   val = map(val, 0, 300, 0, 180);     
   myservo.write(val);                      
   poloha = map(val, 0, 180, 0, 100);
    // text display text
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Teplota       Poloha%_____________________");   
  display.display();
  display.setTextSize(2);
  display.setCursor(0,17);
  display.println(thermocouple.readCelsius()-2);   
  display.display();
  display.setTextSize(2);
  display.setCursor(85,17);
  display.println(poloha);   
  display.display();
  delay(3000);
  display.clearDisplay();

}