• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
rower elektryczny sterowanie
#1
Witam wszystkich , mam mały problemik z programem -jestem początkującym w temacie Arduino

Użyte części
Mega 2560 r3
DS 3231
tft 2.4 Schield
acs 712 30a
2 relay module x2
read swich (kontrakton)

obecnie mam wpisane tylko przyciski dotykowe, sterowaniem Relay module i zegar ds3231 ,ale jest z tym problem ,a mianowicie -gdy nie ma zegara wszystko ładnie chodzi dotyk ON - OFF załączanie od razu relay 1234 ale gdy dopisze zegar DS3231 przyciski źle reagują (dopiero po chwili ),więc co jest nie tak , proszę o wyrozumiałość i poprawienie oraz pokierowanie w dobrą strone . Dziękuje i pozdrawiam wszystkich

Kod:
#include <TimerOne.h>


#include <mega_24_shield.h>
#include <uno_24_shield.h>

#include <Wire.h>
#include <swtft.h>
#include <DS3231.h>
#include <EEPROM.h>
#include <SPI.h>
#include <TouchScreen.h>
#include <Adafruit_GFX.h> // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define    BLACK   0x0000
#define    BLUE    0x001F
#define    RED     0xF800
#define    GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define BLACK   0x0000
#define WHITE   0xFFFF
#define RED     0xF800
#define GREEN   0x07E0
#define BLUE    0x001F
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define GREY    0x2108
    #define RED2RED 0
   #define GREEN2GREEN 1
   #define BLUE2BLUE 2
   #define BLUE2RED 3
   #define GREEN2RED 4
   #define RED2GREEN 5
 DS3231 clock;
RTCDateTime dt;
#include <OneWire.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define YP A1
#define XM A2
#define YM 7
#define XP 6
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);  
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
int in1 = 30;
int in2 = 31;
int in3 = 32;
int in4 = 33;
int valor_botao1 = 0;
int valor_botao2 = 0;
int valor_botao3 = 0;
int valor_botao4 = 0;
int valor_botao5 = 0;



#define reed A9//pin connected to read switch


void setup() {
 
 pinMode(in1, OUTPUT);
 digitalWrite(in1, HIGH);
 pinMode(in2, OUTPUT);
 digitalWrite(in2, HIGH);
 pinMode(in3, OUTPUT);
 digitalWrite(in3, HIGH);
 pinMode(in4, OUTPUT);
 digitalWrite(in4, HIGH);
 Serial.begin(9600);
   tft.begin(0x6809);
   tft.fillScreen(BLACK);
   tft.setRotation(3);
   clock.begin();
   delay(125);
   Wire.begin();
 pinMode(13, INPUT);
 pinMode(A9,INPUT);


zegar();
botoes();


}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop()
{
zegar();

 TSPoint p = ts.getPoint();

 pinMode(XM, OUTPUT);
 pinMode(YP, OUTPUT);
 
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
 {
   p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
   p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
 
   if (p.y >0 && p.y <40 )
   {
      if (p.x < 50)
      {
        //Testa botao LED Branco
        if (valor_botao1 == 0)
        {
          tft.fillRect(260, 30, 50, 30, GREEN);
          digitalWrite(in1, LOW);
          tft.setCursor(274, 38);
          tft.setTextColor(BLACK);
         tft.setTextSize(2);
          tft.println("ON ");
          delay(500);
          valor_botao1 = !valor_botao1;
        }
        else
        {
          tft.fillRect(260, 30, 50, 30, RED);
          digitalWrite(in1, HIGH);
          tft.setCursor(270, 38);
          tft.setTextColor(BLACK);
         tft.setTextSize(2);
          tft.println("OFF ");
          delay(500);
          valor_botao1 = !valor_botao1;
        }
      }
      else if (p.x < 120)
      {
        //Testa botao LED Azul
        if (valor_botao2 == 0)
        {
          tft.fillRect(260, 65, 50, 30, GREEN);
          digitalWrite(in2, LOW);
          tft.setCursor(274, 72);
          tft.setTextColor(BLACK);
         tft.setTextSize(2);
          tft.println("ON ");
          delay(500);
          valor_botao2 = !valor_botao2;
        }
        else
        {
          tft.fillRect(260, 65, 50, 30, RED);
          digitalWrite(in2, HIGH);
          tft.setCursor(270, 72);
          tft.setTextColor(BLACK);
         tft.setTextSize(2);
          tft.println("OFF ");
          delay(500);
          valor_botao2 = !valor_botao2;
        }
      }
      else if (p.x < 160)
      {
        //Testa botao LED Verde
        if (valor_botao3 == 0)
        {
          tft.fillRect(260, 100, 50, 30, GREEN);
          digitalWrite(in3, LOW);
          tft.setCursor(274, 107);
          tft.setTextColor(BLACK);
         tft.setTextSize(2);
          tft.println("ON ");
          delay(500);
          valor_botao3 = !valor_botao3;
        }
        else
        {
          tft.fillRect(260, 100, 50, 30, RED);
          digitalWrite(in3, HIGH);
          tft.setCursor(270, 107);
          tft.setTextColor(BLACK);
         tft.setTextSize(2);
          tft.println("OFF ");
          delay(500);
          valor_botao3 = !valor_botao3;
        }
      }
      else if (p.x < 200)
      {
        //Testa botao LED Amarelo
        if (valor_botao4 == 0)
        {
          tft.fillRect(260, 135, 50, 30, GREEN);
          digitalWrite(in4, LOW);
          tft.setCursor(274, 142);
          tft.setTextSize(2);
          tft.setTextColor(BLACK);
          tft.println("ON ");
          delay(500);
          valor_botao4 = !valor_botao4;
        }
        else
        {
          tft.fillRect(260, 135, 50, 30, RED);
          digitalWrite(in4, HIGH);
          tft.setCursor(270, 142);
          tft.setTextColor(BLACK);
          tft.setTextSize(2);
          tft.println("OFF ");
          delay(500);
          valor_botao4 = !valor_botao4;
         
       
       
       }
      }
   }
 }
 
}
 
 
void botoes()
{
 //Texto botoes
 tft.fillScreen(BLACK);
 tft.setRotation(3);
 tft.setTextSize(1);
 tft.setCursor(210, 40);
 tft.setTextColor(YELLOW);
 tft.println("led P/T");
 tft.setCursor(210, 75);
 tft.setTextColor(GREEN);
 tft.println("PAS");
 tft.setCursor(210, 110);
 tft.setTextColor(BLUE);
 tft.println("Silnik");
 tft.setTextColor(WHITE);
 tft.setCursor(210, 145);
 tft.print("El wire");
 
 
 
 //Desenha botoes
 tft.setTextColor(RED);
 tft.fillRect(260, 30, 50, 30, RED);
 tft.fillRect(260, 65, 50, 30, RED);
 tft.fillRect(260, 100, 50, 30, RED);
 tft.fillRect(260, 135, 50, 30, RED);
 
 
}

void zegar(){
 dt = clock.getDateTime();
 tft.setCursor(2, 225);
 tft.setTextColor(WHITE,BLACK);
 tft.setTextSize(1);
 tft.print("Data");
 tft.setCursor(35, 225);
 tft.setTextColor(RED,BLACK);
 tft.setTextSize(2);
 tft.print(dt.year);   tft.print(":");
 tft.print(dt.month);  tft.print(":");
 tft.print(dt.day);    tft.print(" ");
 
 tft.setCursor(160, 225);
 tft.setTextColor(WHITE,BLACK);
 tft.setTextSize(1);
 tft.print("Time");
 tft.setCursor(195, 225);
 tft.setTextColor(RED,BLACK);  tft.setTextSize(2);
 tft.print(dt.hour);   tft.print(":");
 tft.print(dt.minute); tft.print(":");
 tft.print(dt.second); tft.println("");
 tft.setCursor(206, 202);
 tft.setTextColor(WHITE,BLACK);
 tft.setTextSize(1);
 tft.print("Temp");
 tft.setCursor(230, 200);
 tft.setTextColor(GREEN,BLACK);
 tft.setTextSize(2);
 clock.forceConversion();

 tft.print(" ");
 tft.println(clock.readTemperature());
}
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości