woensdag 14 oktober 2015

Markerprinter - first draws

The project is getting somewere:


dinsdag 29 september 2015

markerprinter_UPDATE

size/length arms is scaled to model
serial connection/sending data to arduino

connected servo to arduino and so far all works fine
on the image the marker follows the purple line, angle values are printed on screen and send serial to arduino (at the moment only one side)

 

PROCESSING:
markerPrinter mprint1, mprint2;
float move_x, move_y, counter;
int curmillis, prevmillis;

void setup (){
  size(200,300);
  //setup mprint
  mprint1 = new markerPrinter(10, 70, 70, 'l');
  mprint2 = new markerPrinter(-10, 70, 70, 'r');
  move_x = 0;
  //serial
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  //delay
  curmillis = millis ();
  prevmillis = curmillis;

}

void draw (){
  curmillis = millis ();
  if (curmillis - prevmillis > 20){
    fill (200);
    rect (0, 0, width, height);
    fill (0);
    text (width+"---"+height, 20, height-40);
    for (int i = 0; i < width; i++){
      stroke (250, 0, 250);
      point(i, 130+30*sin (radians (i)));
    }
    move_y = 130+30*sin (radians (move_x));
    mprint1.update(move_x, move_y);
    mprint2.update(move_x, move_y);
    mprint1.display();
    mprint2.display();
    fill (0);
    text ("left : "+degrees (mprint1.angle_sh), width-120, height-50);
    text ("right: "+degrees (mprint2.angle_sh), width-120, height-25);
    myPort.write(int(degrees(mprint2.angle_sh)));
    move_x++;
    if (move_x >= width){
      //noLoop(); //stop when x = width
      move_x = 0;
    }
    prevmillis = curmillis;
  }
}

void mousePressed(){

}

class markerPrinter{
  PVector center = new PVector ();   //position center acxes
  PVector marker = new PVector ();   //position marker
  PVector arms = new PVector ();     //(|arm1|, |arm2|) length arms
  PVector arm1 = new PVector ();     //position hinge
  PVector arm2 = new PVector ();     //position marker, caculated, used to draw arm 2
  char side;           //position servo vs center
  float offsetX;       //offsetX servo vs centerpoint
  float line_sm;       //virtual line marker to servo
  float angle_m;       //angle between X and line_sm
  float angle_mh;      //angle between line_sm and arm1
  float angle_sm;      //angle between arm1 and arm2
  float angle_sh;      //new angle between arm1 and X

  markerPrinter(float tempoffx, float temparm1, float temparm2, char temps){
    offsetX = tempoffx;
    center.set(width/2-offsetX, 50);
    arms.set(temparm1, temparm2);
    side = temps;
  }

  void update(float temp_mx, float temp_my){
    //set markervalue's
    marker.set (temp_mx-center.x, temp_my-center.y);
    //safety position marker.y > position servo.y+10 to avoid collapse marker/servo
    if (marker.y < 10){
      marker.y = 10;
    }
    //calculations angles
    line_sm = sqrt (sq (marker.x)+sq (marker.y));
    angle_m = acos (marker.x/line_sm);
    switch (side){
      case 'l':
        angle_mh = acos ((sq (arms.y)-sq (arms.x)-sq (line_sm))/(-2*arms.x*line_sm));
        angle_sm = acos ((sq (line_sm)-sq (arms.x)-sq (arms.y))/(-2*arms.x*arms.y));
        break;
      case 'r':
        angle_mh = -acos ((sq (arms.y)-sq (arms.x)-sq (line_sm))/(-2*arms.x*line_sm));
        angle_sm = -acos ((sq (line_sm)-sq (arms.x)-sq (arms.y))/(-2*arms.x*arms.y));
        break;
    }
    angle_sh = angle_m + angle_mh;
    //calculations needed for displaying
    arm1.x = arms.x*cos (angle_sh);
    arm1.y = arms.x*sin (angle_sh);
    arm2.x = arms.y*cos (angle_sm-(PI-angle_sh));
    arm2.y = arms.y*sin (angle_sm-(PI-angle_sh));
   
  }

  void display(){
    pushMatrix ();
    translate (center.x, center.y);
    stroke (180);
    line (-center.x, 0, width, 0);   //X-acxe servo
    //line (0, -center.y, 0, height);  //Y-acxe servo
    //stroke (255, 0, 0, 25);
    //line (0, 0, marker.x, marker.y ); //virtual line servomarker
    stroke (0, 0, 255);
    line (0, 0, arm1.x, arm1.y);     //arm1
    translate (arm1.x, arm1.y);      //hingepoint
    line (0, 0, arm2.x, arm2.y);     //arm2
    popMatrix ();
  }
}

ARDUINO:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 90;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.write(pos);
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed!
  }
}

void loop() {
  if (Serial.available() > 0) {
    // read the incoming byte:
    pos = Serial.read();
    myservo.write(pos);
    delay(15);
  }
}

maandag 28 september 2015

markerprinter_update

markerPrinter mprint1, mprint2;
float move_x, move_y, counter;
int curmillis, prevmillis;
void setup (){
  size(400,600);
  mprint1 = new markerPrinter(70, 250, 250, 'l');
  mprint2 = new markerPrinter(-70, 250, 250, 'r');
  curmillis = millis ();
  prevmillis = curmillis;
  move_x = 0;
}

void draw (){
  curmillis = millis ();
  if (curmillis - prevmillis > 200){
    fill (200);
    rect (0, 0, width, height);
    fill (0);
    text (width+"---"+height, 20, height-40);
    for (int i = 0; i < width; i++){
      stroke (250, 0, 250);
      point(i, 400+30*sin (radians (2*i)));
    }
    move_y = 400+30*sin (radians (2*move_x));
    mprint1.update(move_x, move_y);
    mprint2.update(move_x, move_y);
    mprint1.display();
    mprint2.display();
    fill (0);
    text ("left : "+degrees (mprint1.angle_sh), width-150, height-50);
    text ("right: "+degrees (mprint2.angle_sh), width-150, height-25);
    move_x++;
    if (move_x >= width){
      move_x = 0;
      clear ();
    }
    prevmillis = curmillis;
  }
 
}

void mousePressed(){
 
}

class markerPrinter{
  PVector center = new PVector ();   //position center acxes
  PVector marker = new PVector ();   //position marker
  PVector arms = new PVector ();     //(|arm1|, |arm2|) length arms
  PVector arm1 = new PVector ();     //position hinge
  PVector arm2 = new PVector ();     //position marker, caculated, used to draw arm 2
  char side;         //position servo vs center
  float offsetX;     //offsetX servo vs centerpoint
  float line_sm;     //virtual line marker to servo
  float angle_m;     //angle between X and line_sm
  float angle_mh;    //angle between line_sm and arm1
  float angle_sm;    //angle between arm1 and arm2
  float angle_sh;    //angle between arm1 and X
 
  markerPrinter(float tempoffx, float temparm1, float temparm2, char temps){
    offsetX = tempoffx;
    center.set(width/2-offsetX, 50);
    arms.set(temparm1, temparm2);
    side = temps;
  }
 
  void update(float temp_mx, float temp_my){
    marker.set (temp_mx-center.x, temp_my-center.y);
    if (marker.y < 0){
      marker.y = 0;
    }
    line_sm = sqrt (sq (marker.x)+sq (marker.y));
    angle_m = acos (marker.x/line_sm);
    switch (side){
      case 'l':
        angle_mh = acos ((sq (arms.y)-sq (arms.x)-sq (line_sm))/(-2*arms.x*line_sm));
        angle_sm = acos ((sq (line_sm)-sq (arms.x)-sq (arms.y))/(-2*arms.x*arms.y));
        break;
      case 'r':
        angle_mh = -acos ((sq (arms.y)-sq (arms.x)-sq (line_sm))/(-2*arms.x*line_sm));
        angle_sm = -acos ((sq (line_sm)-sq (arms.x)-sq (arms.y))/(-2*arms.x*arms.y));
        break;
    }
    angle_sh = angle_m + angle_mh;
    arm1.x = arms.x*cos (angle_sh);
    arm1.y = arms.x*sin (angle_sh);
    arm2.x = arms.y*cos (angle_sm-(PI-angle_sh));
    arm2.y = arms.y*sin (angle_sm-(PI-angle_sh));
  }
 
  void display(){
    pushMatrix ();
    translate (center.x, center.y);
    stroke (180);
    line (-center.x, 0, width, 0);   //X-acxe servo
    //line (0, -center.y, 0, height);  //Y-acxe servo
    //stroke (255, 0, 0, 25);
    //line (0, 0, marker.x, marker.y ); //virtual line servomarker
    stroke (0, 0, 255);
    line (0, 0, arm1.x, arm1.y);     //arm1
    translate (arm1.x, arm1.y);      //hingepoint
    line (0, 0, arm2.x, arm2.y);     //arm2
    popMatrix ();
  }
}
 

zaterdag 26 september 2015

Markerprinter

PVector marker = new PVector (40, 250);
PVector arms = new PVector (200, 250);
PVector arm1 = new PVector ();
PVector arm2 = new PVector ();
float line_sm;
float angle_m;
float angle_mh;
float angle_sm;
float angle_sh;
void setup (){
 
}
void draw (){
  fill (200, 80);
  rect (0, 0, width, height);
 
  line_sm = sqrt (sq (marker.x)+sq (marker.y));
  angle_m = acos (marker.x/line_sm);
  angle_mh = acos ((sq (arms.y)-sq (arms.x)-sq (line_sm))/(-2*arms.x*line_sm));
  angle_sm = acos ((sq (line_sm)-sq (arms.x)-sq (arms.y))/(-2*arms.x*arms.y));
  angle_sh = angle_m + angle_mh;
  arm1.x = arms.x*cos (angle_sh);
  arm1.y = arms.x*sin (angle_sh);
  arm2.x = arms.y*cos (angle_sm-(PI-angle_sh));
  arm2.y = arms.y*sin (angle_sm-(PI-angle_sh));
 
  pushMatrix ();
  translate (width/2, 200);
  stroke (255, 0, 0);
  line (0, 0, marker.x, marker.y);
  stroke (0, 0, 255);
  line (0, 0, arm1.x, arm1.y);
  translate (arm1.x, arm1.y);
  line (0, 0, arm2.x, arm2.y);
  popMatrix ();
 
  marker.set (mouseX-width/2, mouseY-200);
}

maandag 21 september 2015

gauge clock2

Created another simple gauge class (GaugeII), then used it for a clock



code:

GaugeII second, minute, hour;
int secold, minold, hourold;

void setup(){
  size(800, 270);
  second = new GaugeII(250, 0, 59, 5, "second"); //(width, begin, end, division lines, name gauge)
  minute = new GaugeII(250, 0, 59, 5, "minute");
  hour = new GaugeII(250, 0, 11, 3,  "hour");
  secold = 100;  //val can never be 100, first run will always draw
  minold = 100;
  hourold = 100;
}

void draw(){
  //to save resource, only redraw when time has changed
  if (second() != secold){
    second.update(second());
    pushMatrix();
    translate(530, 10);
    second.display();
    popMatrix();
    secold = second();
  }
  if (minute() != minold){
    minute.update(minute());
    pushMatrix();
    translate(270, 10);
    minute.display();
    popMatrix();
    minold = minute();
  }
  if (hour() != hourold){
    //time received is 24 hour notation, gauge has scale of 12
    if (hour() <= 11){
      hour.update(hour());
    } else {
      hour.update(hour()-12);
    }
    pushMatrix();
    translate(10, 10);
    hour.display();
    popMatrix();
    hourold = hour();
  }
}


class GaugeII{
  PVector gsize;    //gauge(size, rotationpoint needle/scale)
  PVector gneedle;  //needle(size, angle)
  PVector gscale;   //scale(start, stop)
  int gsteps;       //scale, number of steps
  int gline;        //scale, division lines
  String gname;     //name gauge
 
  GaugeII(int temp_size, float temp_start, float temp_stop, int temp_line, String temp_name){
    gsize = new PVector(temp_size, temp_size-(temp_size/10));
    gneedle = new PVector(-7*temp_size/10, 0);
    gscale = new PVector(temp_start, temp_stop);
    gline = temp_line;
    gsteps = int(temp_stop - temp_start)+1;
    gname = temp_name;
  }
 
  void display(){
    //back
    stroke(0);
    strokeWeight(5);
    fill(255);
    rect(0, 0, gsize.x, gsize.x);
    fill(0);
    textAlign(CENTER);
    textSize(14);
    text(gname, gsize.x/4, 20);
   
    //scale
    stroke(0);
    strokeWeight(2);
    for (int i = 0; i < gsteps; i++){
      pushMatrix();
      translate(gsize.y, gsize.y);
      rotate(map(i, gscale.x, gscale.y, 0, HALF_PI));
      if (i%gline == 0){
        line(gneedle.x-5, 0, gneedle.x+5, 0);
        fill(0);
        translate(gneedle.x-10, 0);
        rotate(-HALF_PI);
        textSize(9);
        text(i, 0, 0);
      } else {
        point(gneedle.x, 0);
      } 
      popMatrix();
    }
   
    //needle
    pushMatrix();
    translate(gsize.y, gsize.y);
    rotate(gneedle.y);
    noStroke();
    fill(255, 0, 0);
    ellipseMode(CENTER);
    ellipse(0, 0, 15, 15);
    stroke(255, 0, 0);
    strokeWeight(2);
    line(0, 0, gneedle.x, 0);
    noStroke();
    popMatrix();
  }
 
  void update(float tempval){
    float gvalue = tempval;
    gneedle.y = map(gvalue, gscale.x, gscale.y, 0, HALF_PI);
  }
}

vrijdag 18 september 2015

gauge clock UPDATED

gauge clock

created a class to draw a simple gauge, then used it to show the time

screen shot:



Update:
- added scale values
- scale quotation can be altered at creation



code:

Gauge second, minute, hour;
int secold, minold, hourold;

void setup(){
  size(790, 210);
  second = new Gauge(250, 0, 59, 5, "second"); //(width, begin, end, quotation scale, name gauge)
  minute = new Gauge(250, 0, 59, 5, "minute");
  hour = new Gauge(250, 0, 11, 3,  "hour");
  secold = 100;  //val can never be 100, first run will always draw
  minold = 100;
  hourold = 100;
}

void draw(){
  //to save resource, only redraw when time has changed
  if (second() != secold){
    second.update(second());
    pushMatrix();
    translate(530, 10);
    second.display();
    popMatrix();
    secold = second();
  }
  if (minute() != minold){
    minute.update(minute());
    pushMatrix();
    translate(270, 10);
    minute.display();
    popMatrix();
    minold = minute();
  }
  if (hour() != hourold){
    //time received is 24 hour notation, gauge has scale of 12
    if (hour() <= 11){
      hour.update(hour());
    } else {
      hour.update(hour()-12);
    }
    pushMatrix();
    translate(10, 10);
    hour.display();
    popMatrix();
    hourold = hour();
  }
}

class Gauge{
  PVector gsize;  //width & height gauge
  PVector gscale;  //start & end value scale
  PVector gneedle; //length & angle needle
  int gsteps;
  float gline;
  String gname;
   
  Gauge(float tempx, float templow, float temphigh, float templine, String tempname){
    float gwidth = tempx;
    float gheight = 26*tempx/35;
    float glow = templow;
    float ghigh = temphigh;
    gline = templine;
    gname = tempname;
    gsteps = int(temphigh - templow) + 1;
    gsize = new PVector(gwidth, gheight);
    gscale = new PVector(glow, ghigh);
    gneedle = new PVector(5*gsize.y/8, map(second(), 0, 59, radians(35), radians(145)));
  }
 
  void display(){
    noStroke();
    //backcover
    fill(50);
    rect(0, 0, gsize.x, gsize.y);
    fill(255);
    textAlign(CENTER);
    textSize(14);
    text(gname, gsize.x/2, 15);
    //scale
    stroke(255, 200);
    strokeWeight(2);
    for (int i = 0; i < gsteps; i++){
      pushMatrix();
      translate(gsize.x/2, 11*gsize.y/12);
      rotate(PI + map(i, gscale.x, gscale.y, radians(35), radians(145)));
      if (i%gline == 0){
        line(gneedle.x-5, 0, gneedle.x+5, 0);
        translate(gneedle.x+10, 0);
        rotate(HALF_PI);
        textSize(9);
        text(i, 0, 0);
      } else {
        point(gneedle.x, 0);
      } 
      popMatrix();
    }
    noStroke();
    //needle
    stroke(255, 0, 0);
    strokeWeight(3);
    pushMatrix();
    translate(gsize.x/2, 11*gsize.y/12);
    rotate(PI + gneedle.y);
    line(0, 0, gneedle.x, 0);
    popMatrix();
    noStroke();
    //frontcover
    fill(150, 180);
    rect(0, 4.5*gsize.y/6, gsize.x, 1.5*gsize.y/6);
    fill(255, 0, 0);
    ellipseMode(CENTER);
    ellipse(gsize.x/2, 11*gsize.y/12, 10, 10);
  }
 
  void update(float tempgval){
    float gvalue = tempgval;
    gneedle.y = map(gvalue, gscale.x, gscale.y, radians(35), radians(145));
  }
}

dinsdag 10 februari 2015

Simple thermostat Arduino - Processing

bought an arduino starterkit and started playing...

once I got the LCD working, I combined it with the temp sensor and created a simple thermostat. Then I couldn't resist to make a processing sketch to draw a curve with received temperature value's.



There are 3 main screens, switched by the up/down buttons, 
the value's are set by the left/right buttons
(for more info about connecting a lcd to arduino http://arduino.cc/en/Tutorial/LiquidCrystal)


Arduino sketch:
#include <LiquidCrystal.h>

// LCD, initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //pins(rs, enable, d4, d5, d6, d7)
byte lcdCharDegree[8] = {B00000, B00111, B00101, B00111, B00000, B00000, B00000};  //LCD "°"
byte lcdCharLeft[8]   = {B00000, B00010, B00110, B01110, B00110, B00010, B00000};  //LCD "<"
byte lcdCharRight[8]  = {B00000, B01000, B01100, B01110, B01100, B01000, B00000};  //LCD ">"

//button
const int btnUp = 6;
const int btnRight = 7;
const int btnDown = 8;
const int btnLeft = 9;
int btnMenu = 0;   //needed to change menu item
int btnSet;        //needed to change settings

//temperature
const int sensorPin = A0;   //input pin for tempsensor
float temperature;          //temperature value in °C
long previousMillis = 0;    //needed for 'measure-delay'
long interval = 1000;       //measure-delay (1 sec)

//Thermostat ON-OFF
boolean thermostatStatus = LOW; //thermostat is turned off at startup
String textStatus;              //String printed on LCD

//Set temperature
float tempSet = 20.00;  //set 20.00°C at startup

//ledpin variables (2color-led instead of relais)
const int ledAPin = 10;
const int ledCPin = 13;


void setup() {
  Serial.begin(9600);
  // set up the number of columns and rows on the LCD 
  lcd.begin(16, 2);
  
  //create special charset for LCD
  lcd.createChar(0, lcdCharDegree);
  lcd.createChar(1, lcdCharLeft);
  lcd.createChar(2, lcdCharRight);
  // setup buttonpins as input
  pinMode(btnUp,INPUT);
  pinMode(btnDown,INPUT);
  pinMode(btnLeft,INPUT);
  pinMode(btnRight,INPUT);
  
  //setup ledpins as output
  pinMode(ledAPin,OUTPUT);
  pinMode(ledCPin,OUTPUT);
  
  // Print a message on startup
  lcd.setCursor(0, 0);          // set cursor to column 0, line 0 (top line)  
  lcd.print("THERMOSTAT");      // print to LCD
  lcd.setCursor(0, 1);          // set cursor to column 0, line 1 (bottom line)
  lcd.print("Version 0130.0");  //print to LCD
  delay(2000);                  //delay keeps startup message on LCD for 2 sec
  lcd.clear();                  //clear LCD before starting loop()
}

void loop() {
  //switch led when changing between menu-options
  wndSwitchLed(); 
  //switch menu-screen
  switch (btnMenu){              /* int btnMenu holds value 0 or 1 or 2
                                  * when btnUp/btnDown is pressed, 1 is added/removed to value btnMenu
                                  */
    case 0:
      wndScreenTopical();
      break;
    case 1:
      wndScreenOnOff();
      break;
    case 2:
      wndScreenTempSet();
  }
}

void wndScreenTopical(){
  //static text, printed once on LCD
  //variable text, update print until menu-option is changed
  //static text
  lcd.setCursor(0, 0);
  lcd.print("Topical Temp.");
  lcd.setCursor(9, 1);
  lcd.print(temperature);
  lcd.setCursor(14, 1);
  lcd.write(byte(0));
  lcd.setCursor(15, 1);
  lcd.print("C");
  //variable text
  while ((digitalRead(btnUp) == LOW) && (digitalRead(btnDown) == LOW)){  //check buttons, if up/down is pressed leave                                                                                                                                    loop and change screen/ledstatus
                                                                                                                         //when left/right is pressed change value and loop
    wndGetTemperature();      //get temperature
    lcd.setCursor(9, 1);      //set cursor back in position
    lcd.print(temperature);   //print topical temperature to LCD
    wndSwitchLed();           //change led color when temperature > tempSet
    wndBtnPressed();          //check buttons, if button is pressed, change screen/value
  } 
}  

void wndScreenOnOff(){
  //static text
  lcd.setCursor(0, 0);
  lcd.print("Thermostat");
  lcd.setCursor(0, 1);
  lcd.write(byte(1));
  lcd.setCursor(15, 1);
  lcd.write(byte(2));
  //variable text
  while ((digitalRead(btnUp) == LOW) && (digitalRead(btnDown) == LOW)){  //check buttons, if up/down is pressed                                                                                                                                               change screen/ledstatus
                                                                                                                       // when left/right is pressed change value and loop
    if (thermostatStatus){
      textStatus = "ON ";
    } else {
      textStatus = "OFF";
    }
    lcd.setCursor(6, 1);
    lcd.print(textStatus);
    wndBtnPressed();
  }
}

void wndScreenTempSet(){
  //static text
  lcd.setCursor(0, 0);
  lcd.print("Set Temperature");
  lcd.setCursor(0, 1);
  lcd.print("-");
  lcd.setCursor(15, 1);
  lcd.print("+");
  //variable text
  while ((digitalRead(btnUp) == LOW) && (digitalRead(btnDown) == LOW)){  //loop until menu-option is changed
    lcd.setCursor(4, 1);    //set cursor back in position
    lcd.print(tempSet);     //print variable value
    wndBtnPressed();        //check buttons, if up/down is pressed leave loop and change screen
                            //               if left/right is pressed change value and loop
  }
}

void wndGetTemperature(){
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;
    int sensorVal = analogRead(sensorPin);
    float voltage = (sensorVal/1024.0) * 5.0;  // convert the ADC reading to voltage
    temperature = (voltage - .5) * 100;        /* convert to °C
                                                * the sensor changes 10 mV per degree
                                                * the datasheet says there's a 500 mV offset
                                                * ((volatge - 500mV) times 100)*/
    Serial.println(temperature);
  }
}

void wndBtnPressed(){
  if (digitalRead(btnUp)){
    if (btnMenu != 0){                   //0 is lowest value for btnMenu
      lcd.clear();
      btnMenu = btnMenu--;
    }
  } else if (digitalRead(btnDown)){
    if (btnMenu != 2){                  //2 is highest value for btnMenu
      lcd.clear();
      btnMenu = btnMenu++;
    }
  } else if (digitalRead(btnLeft) && btnMenu == 1){ //btnleft in thermostat ON/OFF
    if (thermostatStatus){                          //thermostat ON?
      thermostatStatus = LOW;                       //turn OFF
    }
  } else if (digitalRead(btnLeft) && btnMenu == 2){  //btnleft in set temperature, switch-temperature - 0.5°C
    if (tempSet > 0){                                //tempset cannot go below 0°c
      tempSet = tempSet - 0.5;                       //if button is pressed substract 0.5 from settemp
      delay(200);                                    //delay 0.2 sec, otherwise value subracts to fast
    }
  } else if (digitalRead(btnRight) && btnMenu == 1){  //btnright in thermostat ON/OFF
    if (thermostatStatus == LOW){                     //thermostat OFF?
      thermostatStatus = HIGH;                        //turn ON
    }
  } else if (digitalRead(btnRight) && btnMenu == 2){  //btnright in set temperature, switch-temperature + 0.5°C
    if (tempSet < 100){                               //tempset cannot go above 100°c
      tempSet = tempSet + 0.5;                        //if button is pressed add 0.5 from settemp
      delay(200);                                     //delay 0.2 sec, otherwise value adds to fast
    }
  }
}

void wndSwitchLed(){
  if (tempSet > temperature && thermostatStatus){
    digitalWrite(ledAPin, LOW);
    digitalWrite(ledCPin, HIGH);
  } else {
    digitalWrite(ledCPin, LOW);
    digitalWrite(ledAPin, HIGH);
  }
}

processing:

import processing.serial.*;

Serial myPort;            // Serial port object
int lf = 10;              // Linefeed in ASCII-code, when linefeed is received, string is complete
String myString = null;   // empty string wich input data from arduino is saved in, when string is completed its converted to                                                 float
float num;                // float converted from received string
float [] valScreen = new float [30];   //30 temperatures values
int lengthScreen = 30;
PShape valCurve;          //Shape object value curve



void setup(){
  size(640,480,P2D);
  frameRate(1);                                            //every second the screen is updated once
  myPort = new Serial(this, Serial.list()[0], 9600);       //setup serial object for serial communication
  myPort.clear();                                          //empty serial buffer
  for (int i = 0; i < lengthScreen; i ++){                 //fill temp value array with 0's
    valScreen[i]=0;    
  }
}

void draw(){
                                                            
                                                            
  for (int i = 0; i < lengthScreen; i++){                   // replace temperature value's in array one place
    if (i < lengthScreen-1){                                // oldest is lost, new value is added from data-input
      valScreen[i]=valScreen[i+1];
    } else {
      while (myPort.available() > 0) {                      // read data while avaible
        myString = myPort.readStringUntil(lf);              // string ends when linefeed is received
        if (myString != null) {                             // when string is not empty
          print(myString);                                  // Prints String to console-window
          num=float(myString);                              // Converts string to float
          valScreen[i]= num*(-4);                           // New value, for visual reasons multiply by -4, negative so higher value is 
                                                                               drawn above lower value, 
                                                            // 4* real value because difference between value's are small 
        }
      }
      myPort.clear();                                       // clear serial buffer 
      background(200);                                      
      stroke(0, 0, 255);
      line(25, height/2, 480, height/2);                    // draw X-axis
      line(25, height/2-150, 25, height/2+20);              // draw Y-axis
    }
  }
  valCurve = createShape();                                 // create curve-shape
  valCurve.beginShape();
  valCurve.noFill();
  valCurve.strokeWeight(2);
  valCurve.stroke(200,0,0);
  for (int i = 0; i < lengthScreen; i++){                   // for loop for reading curve-data
    valCurve.curveVertex(15*i, valScreen[i]);
    if (i == 0 || i == lengthScreen-1){                     // at start/end curve ad same value once again (more info see Vertex in Processing-Refference)
      valCurve.curveVertex(15*i, valScreen[i]);
    }
    noStroke();                                    
    fill(0, 0, 0);
    ellipse(25+(15*i), height/2+valScreen[i], 5, 5);        // value points on curve, code is not part of shape(curve) but is placed here because of 'for-loop'
  }
  valCurve.translate(25,height/2);                          // move shape object to right position
  valCurve.endShape();
  shape(valCurve);                                          // draw curve
  textSize(15);
  fill(0, 0, 200);
  textAlign(RIGHT);
  text("Realtime temp: "+valScreen[lengthScreen-1]/(-4)+"°C", 480, height/2+50); //text output on screen
    
}