سلام دوستان من یه مدار کنترل موتور dc دارم که سرعتش با اپتوکانتر خونده میشه و روی یک lcd 1.44 tft نمایش داده میشه ( lcd مدل st7735 که با بروتکل SPI کار میکنه) برنامه اپتوکانتر با اینتراپت تایمر 1 نوشته شده و وقتی زمانش رو روی 1s میذارم موتور نمیچرخه و وقتی زمان رو کم میکنم موتور میچرخه ولی lcd دیگه نمایش نمیده، ممنون میشم کمک کنین
این هم کد برنامه:
این هم کد برنامه:
#define sclk 13 // Don't change
#define mosi 11 // Don't change
#define dc 8
#define PWM 9
#define STEP 3
#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735_AS.h>// Hardware-specific library
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <TimerOne.h>
Adafruit_ST7735_AS tft = Adafruit_ST7735_AS(0 ,dc, 14); // Invoke custom library
unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;
int a=0,b=0 ;
static int counter = 0;
char myString[19];
void setup(void)
{
pinMode(PWM,OUTPUT);
tft.initR(INITR_BLACKTAB);
tft.setRotation(4);
pinMode(STEP, INPUT);
attachInterrupt(1, up, FALLING);
Serial.begin(9600);
Timer1.initialize(1000);
Timer1.attachInterrupt(up);
}
void loop() {
analogWrite(PWM,100);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_RED);
tft.drawString( "MFT" ,41 ,4 ,2);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(4,40);
tft.print("motor dc");
tft.setCursor(4,70);
tft.print("RPM:");
tft.setCursor(60,70);
tft.setTextSize(2);
b = PWM;
tft.print(b );
//int xpos=0;
//xpos+=tft.drawString("are",4,64,2);
//tft.drawChar(127,xpos,64,2);
delay(100);
//b = a++;
}
void up()
{
detachInterrupt(1);
Serial.println((counter/40)*60);
counter=0;
attachInterrupt(1, read_rotary, FALLING);
//Serial.println(counter*8/40*60);
}
void read_rotary(void)
{
counter++;
}
#define mosi 11 // Don't change
#define dc 8
#define PWM 9
#define STEP 3
#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735_AS.h>// Hardware-specific library
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <TimerOne.h>
Adafruit_ST7735_AS tft = Adafruit_ST7735_AS(0 ,dc, 14); // Invoke custom library
unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;
int a=0,b=0 ;
static int counter = 0;
char myString[19];
void setup(void)
{
pinMode(PWM,OUTPUT);
tft.initR(INITR_BLACKTAB);
tft.setRotation(4);
pinMode(STEP, INPUT);
attachInterrupt(1, up, FALLING);
Serial.begin(9600);
Timer1.initialize(1000);
Timer1.attachInterrupt(up);
}
void loop() {
analogWrite(PWM,100);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_RED);
tft.drawString( "MFT" ,41 ,4 ,2);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(4,40);
tft.print("motor dc");
tft.setCursor(4,70);
tft.print("RPM:");
tft.setCursor(60,70);
tft.setTextSize(2);
b = PWM;
tft.print(b );
//int xpos=0;
//xpos+=tft.drawString("are",4,64,2);
//tft.drawChar(127,xpos,64,2);
delay(100);
//b = a++;
}
void up()
{
detachInterrupt(1);
Serial.println((counter/40)*60);
counter=0;
attachInterrupt(1, read_rotary, FALLING);
//Serial.println(counter*8/40*60);
}
void read_rotary(void)
{
counter++;
}