#include <SPI.h>
#include <Adafruit_GFX.h>
//#include <Adafruit_SH1106.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 13
#define SCREEN_ADDRESS 0x3C
//Adafruit_SH1106 OLED(OLED_RESET);
Adafruit_SSD1306 OLED(128, 64, &Wire, OLED_RESET);
#if (SH1106_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SH1106.h!");
#endif
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);// LCD PİNLERİ SDA=20 , SCL =21
#include <AccelStepper.h>
AccelStepper Xmotor(1, 2, 5); // 1 = easy driver step dır
#define MOTORAC 8
#define XMOTOR_STEPS 200
#define XMICROSTEPS 4
int xonceki = 0;
int long xyeni = 0;
int HIZonceki = 0;
int long HIZyeni = 0;
const int potXmotor = A8;
int potXmotorDurum = 0;
int potXmotorPozisyon = 0;
//---------------------------------------
const int potHIZ = A12;
int HIZ=100;
int parazit = 100;
int potHIZDurum ;
#define buton1 14
#define buton2 15
#define buton3 16
#define buton4 17
#define buton5 18
#define buton6 19
byte but1durum;
byte but2durum;
byte but3durum;
byte but4durum;
byte but5durum;
byte but6durum;
uint8_t M1 = 13;
//---------------------------------------------------
void butonOku() {
but1durum = digitalRead(buton1);
but2durum = digitalRead(buton2);
but3durum = digitalRead(buton3);
but4durum = digitalRead(buton4);
but5durum = digitalRead(buton5);
but6durum = digitalRead(buton6);
}
//------------------------------------------------------------
void MOTileri(){
Xmotor.runToNewPosition(potXmotorPozisyon);
lcd.setCursor(0, 1); lcd.print("MOTOR ILERI ");
}
//-*------------------------------------------------------------------
void MOTgeri(){
lcd.setCursor(0, 1); lcd.print("MOTOR GERI ");
Xmotor.runToNewPosition(potXmotorPozisyon);
}
//-----------------------------------------------------------
void setup() {
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
OLED.begin(SSD1306_SWITCHCAPVCC, 0x3C);
potHIZDurum = analogRead(potHIZ);
OLED.display(); delay(200); OLED.clearDisplay();
lcd.setCursor(0, 1); lcd.print("ARDUiNO KONTROL");
pinMode(buton1, INPUT_PULLUP);
pinMode(buton2, INPUT_PULLUP);
pinMode(buton3, INPUT_PULLUP);
pinMode(buton4, INPUT_PULLUP);
pinMode(buton5, INPUT_PULLUP);
pinMode(buton6, INPUT_PULLUP);
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
//------------------------------------------------------
void STEP_MOTOR_TEST() {
OLED.clearDisplay();
potHIZDurum = analogRead(potHIZ);
if ((potHIZDurum > HIZonceki + parazit*2) || (potHIZDurum < HIZonceki - parazit*2) ) {
HIZyeni = potHIZDurum;
HIZ = map(HIZyeni, 0, 1023, 100, 5000);
HIZonceki = HIZ;
}
OLED.setTextSize(2);OLED.setTextColor(WHITE);
OLED.setCursor(42, 30); OLED.print("HIZ"); OLED.display();
OLED.drawRoundRect(10, 52, 102, 9, 2, WHITE);
//M1 = constrain(M1 + potXmotorDurum, 0, 100);
OLED.fillRect(11, 53, HIZ/50, 7, WHITE);
OLED.display();
//*********************************
potXmotorDurum = analogRead(potXmotor);
/* if ((potXmotorDurum > xonceki + parazit) || (potXmotorDurum < xonceki -parazit)) {
xyeni = potXmotorDurum;
potXmotorPozisyon = map(xyeni, 0, 1023, 0, 7200);
xonceki = potXmotorPozisyon;}*/
xyeni= map( potXmotorDurum, 0, 1023, 1, 6);
if (xyeni==1)
potXmotorPozisyon = 200;
if (xyeni==2)
potXmotorPozisyon = 400;
if (xyeni==3)
potXmotorPozisyon = 800;
if (xyeni==4)
potXmotorPozisyon = 1600;
if (xyeni==5)
potXmotorPozisyon = 3200;
if (xyeni==6)
potXmotorPozisyon = 6400;
butonOku();
lcd.setCursor(0, 0); lcd.print("H=");lcd.println(HIZ);
lcd.setCursor(7, 0);lcd.print("ADM="); lcd.println(potXmotorPozisyon );
lcd.setCursor(0, 1); lcd.print("MOTOR ILERI>>>>>");
Xmotor.setMaxSpeed(HIZ);//STEP MOTORLARIN HIZ AYARI
Xmotor.setAcceleration(HIZ * 0.8); //STEP MOTORLARIN İVME AYARI
Xmotor.runToNewPosition(potXmotorPozisyon );
delay(500);
lcd.setCursor(0, 1); lcd.print("MOTOR GERi<<<<<<");
Xmotor.runToNewPosition(0);
delay(500);
}
void loop() {
STEP_MOTOR_TEST();
}
Loading
ssd1306
ssd1306