SHARE
TWEET

Untitled

a guest Oct 21st, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "labduino.h"
  2. #include <TimerThree.h>
  3.  
  4. int temperatura;
  5. unsigned char Pwm_Set = 0;
  6.  
  7. int kp = 0.6;
  8. int uchyb = 0;
  9. int temperatura_zadana = 60;
  10. int zaklocenie;
  11.  
  12.  
  13. void Timer3ISR() {
  14.   static boolean output = HIGH;
  15.  
  16.   if (temperatura_zadana == 0) digitalWrite(LED1, 0);
  17.   else digitalWrite(LED1, 1);
  18.   if (!digitalRead(SW1) & temperatura_zadana >= 5) temperatura_zadana -= 5;  // zmniejsz temp.
  19.  
  20.   if (temperatura_zadana == 65) digitalWrite(LED2, 0);
  21.   else digitalWrite(LED2, 1);
  22.   if (!digitalRead(SW2) & temperatura_zadana <= 60) temperatura_zadana += 5;  // zmniejsz temp.
  23.  
  24.   if (digitalRead(SW3)) digitalWrite(LED3, 1);
  25.   else { // dodaj zakłócenie
  26.     digitalWrite(LED3, 0);
  27.     zaklocenie = rand() % 10;
  28.     Serial.print("Zaklocenie ma wartosc: ");
  29.     Serial.println(zaklocenie);
  30.   }
  31.  
  32.   uchyb = temperatura_zadana - temperatura;
  33.   Pwm_Set += uchyb;
  34.   analogWrite(M1_EN, Pwm_Set);
  35.   analogWrite(M2_EN, - Pwm_Set);
  36.   analogWrite(M3_EN, Pwm_Set);
  37.   analogWrite(M4_EN, -Pwm_Set);
  38. }
  39.  
  40. void setup() {
  41.   labduinoSetup();
  42.   sensors.begin();
  43.   Timer3.initialize(100000);
  44.   Timer3.attachInterrupt(Timer3ISR);
  45.  
  46.   Serial.begin(9600);
  47.   if (!sensors.getAddress(sensor, 0))   Serial.println("Nie znaleziono chipu DS18B20");
  48. }
  49.  
  50. void loop() {
  51.   temperatura = analogRead(LM35);
  52.   sensors.requestTemperatures();
  53.   float tempC = sensors.getTempC(sensor);
  54.   Serial.println(String(temperatura) + String(" ; ") + String(tempC));
  55.   Serial.print("Temperatura zadana: ");
  56.   Serial.println(temperatura_zadana);
  57.  
  58.  
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top