Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // v 0.6 Mega 2560 Ir + Bluetooth
- #include <IRremote.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Timer.h>
- #include <Servo.h>
- Timer t;
- Servo myservo; // create servo object to control a servo
- IRrecv irrecv(54); // nano-nál 17 - A3, mega 54 - A0
- decode_results results;
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
- #define M1AIrany 51 // 3
- #define M1BIrany 31 // 13 nincs használva
- #define M1Lepes 49 // 4
- #define M2Irany 47 // 5 // Kar forgatás
- #define M2Lepes 45 // 6
- #define M3Irany 43 // 7 // Alkar billentés
- #define M3Lepes 41 // 8
- #define M4Irany 39 // 9 // Csipesz billentés
- #define M4Lepes 37 // 10
- #define M5Irany 35 // 11 // Csipesz forgatás
- #define M5Lepes 33 // 12
- uint8_t hossz=0, IRcode, sbc=0, motor; // sbc - serial buffer counter, value - value from serial1-bluetooth
- uint8_t sbuffer[10]; // serial buffer
- int lepes=10;
- long IRValue=0, oldValue=0, value;
- long M1dest=0, M2dest=0, M3dest=0, M4dest=0, M5dest=0; // destination position
- long M1pos=0, M2pos=0, M3pos=0, M4pos=0, M5pos=0;
- long M1min=-600, M2min=-800, M3min=-1400, M4min=-50, M5min=-250;
- long M1max= 600, M2max= 400, M3max= 1400, M4max= 150, M5max= 250;
- uint8_t M1dir, M1del, M1delc, M1stepnum; // M1 várakozás, várakozás számláló, lépés
- uint8_t M2dir, M2del, M2delc, M2stepnum;
- uint8_t M3dir, M3del, M3delc, M3stepnum;
- uint8_t M4dir, M4del, M4delc, M4stepnum;
- uint8_t M5dir, M5del, M5delc, M5stepnum;
- // Motorok mozgás parancsai: irány, késleltetés, lépés szám. Ha irány=2 akkor nem lép, de számol
- uint8_t prg=2;
- uint8_t M1clong=57, M1cc=0; // Hány parancsot hajtson végre, 1 parancs 3 byte
- uint8_t M2clong=57, M2cc=0;
- uint8_t M3clong=57, M3cc=0;
- uint8_t M4clong=57, M4cc=0;
- uint8_t M5clong=57, M5cc=0;
- uint8_t M1comm[3][57] = { // 0 - stop, 1 - bal, 2 - jobb; időzítés; lépés száma
- {1,50,50, 2,50,100, 0,50,50, 1,50,100, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 1,50,50, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 1,50,200, 2,50,100, 0,50,25, 2,50,100},
- {1,25,100, 2,25,100, 1,25,100, 2,25,50, 0,25,50, 2,25,50, 0,25,50, 2,25,50, 0,25,50, 2,25,50, 0,25,50, 2,25,50, 0,25,50, 2,25,50, 0,25,50, 2,25,50, 1,25,50, 2,25,50, 1,25,50},
- {1,9,100, 1,9,200, 2,10,100, 0,5,200, 0,5,200, 2,20,200, 1,5,100, 2,20,20, 1,10,50, 1,10,50, 2,20,50, 1,5,100, 2,20,50, 1,10,100, 2,20,50, 1,10,100, 2,20,50, 0,10,100, 0,20,100}
- };
- uint8_t M2comm[3][57] = {
- {2,50,200, 0,50,20, 2,50,50, 0,50,50, 2,50,50, 1,50,100, 2,50,50, 1,50,200, 2,50,50, 1,50,100, 2,50,550, 0,50,150, 2,50,50, 0,50,150, 2,50,50, 1,50,150, 2,50,50, 0,50,50, 2,50,50},
- {1,25,50, 2,25,50, 1,25,100, 2,5,20, 0,25,50, 2,5,20, 0,25,150, 2,5,20, 0,25,150, 2,5,20, 0,25,50, 2,5,20, 0,25,50, 2,5,20, 0,25,50, 2,50,20, 1,25,100, 2,50,20, 1,25,100},
- {0,10,250, 0,10,250, 0,10,250, 2,20,200, 1,5,100, 2,20,50, 1,5,100, 2,20,20, 0,1,50, 2,10,50, 0,5,200, 2,20,50, 1,5,200, 2,10,100, 1,10,50, 2,10,10, 1,10,200, 2,10,10, 1,20,200}
- };
- uint8_t M3comm[3][57] = {
- {1,20,250, 1,20,250, 0,20,250, 2,20,50, 1,20,250, 1,20,250, 1,20,250, 0,20,250, 2,20,100, 1,20,250, 2,20,100, 0,20,250, 2,20,100, 1,20,250, 2,20,100, 1,20,250, 2,20,100, 0,20,250, 2,20,150},
- {1,10,250, 2,10,250, 1,10,250, 2,10,250, 0,10,250, 2,10,20, 0,10,250, 2,10,20, 0,10,250, 2,10,20, 0,10,250, 2,10,20, 0,10,250, 2,10,20, 0,10,250, 2,10,20, 1,10,250, 2,10,20, 1,10,250},
- {0,1,250, 0,1,250, 0,1,250, 0,1,250, 0,1,250, 2,20,200, 0,5,100, 2,20,200, 1,5,50, 1,10,50, 2,20,200, 0,5,100, 2,20,200, 1,10,100, 2,20,200, 1,5,100, 2,20,200, 0,10,100, 2,20,200}
- };
- uint8_t M4comm[3][57] = {
- {1,50,10, 2,50,100, 0,50,10, 2,50,50, 1,50,5, 2,50,50, 0,50,5, 2,50,50, 1,50,10, 2,50,50, 0,50,10, 2,50,50, 1,50,10, 2,50,50, 0,50,10, 2,50,50, 1,50,10, 2,50,50, 0,50,10},
- {1,50,100, 2,50,200, 1,50,100, 2,50,200, 0,50,50, 2,50,200, 0,50,50, 2,50,200, 0,50,50, 2,50,200, 0,50,50, 2,50,200, 0,50,50, 2,50,200, 0,50,50, 2,50,200, 1,50,100, 2,50,200, 1,50,100},
- {1,10,50, 2,200,200, 1,5,100, 2,200,200, 0,5,100, 2,200,200, 0,5,100, 2,200,200, 1,10,50, 1,100,50, 2,200,200, 0,5,100, 2,200,200, 1,10,100, 2,200,200, 1,10,100, 2,200,200, 0,10,100, 2,200,200}
- };
- uint8_t M5comm[3][57] = {
- {1,50,200, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 0,50,50, 2,50,100, 0,50,100},
- {1,25,100, 2,22,200, 1,25,100, 2,25,200, 0,25,50, 2,25,20, 0,25,50, 2,25,20, 0,25,50, 2,25,20, 0,25,50, 2,25,20, 0,25,50, 2,25,20, 0,25,50, 2,25,20, 1,25,100, 2,25,20, 1,25,100},
- // {1,10,50, 2,20,200, 1,5,100, 2,20,200, 0,5,100, 2,20,200, 0,5,100, 2,20,200, 1,10,50, 1,10,50, 2,10,200, 0,5,100, 2,20,200, 1,10,100, 2,20,200, 1,10,100, 2,20,200, 0,10,100, 2,20,200}
- {1,1,200, 2,10,250, 2,10,250, 2,20,20, 0,5,100, 2,20,20, 0,5,100, 2,20,20, 1,10,50, 1,5,50, 2,10,200, 0,5,100, 2,20,200, 0,10,100, 2,20,200, 1,10,100, 2,20,200, 0,10,100, 2,20,200}
- };
- bool M1run=false, M2run=false, M3run=false, M4run=false, M5run=false;
- bool M1btrun=false, M2btrun=false, M3btrun=false, M4btrun=false, M5btrun=false;
- void setup() {
- Serial.begin(115200);
- Serial1.begin(9600);
- delay(500);
- myservo.attach(13);
- lcd.begin(16,2); // lcd alaphelyzetbe állítás
- lcd.clear();
- lcd.print("Start ...");
- int tickEvent = t.every(1, tikkel, 1 );
- pinMode(M1AIrany, OUTPUT);
- pinMode(M1BIrany, OUTPUT);
- pinMode(M1Lepes, OUTPUT);
- pinMode(M2Irany, OUTPUT);
- pinMode(M2Lepes, OUTPUT);
- pinMode(M3Irany, OUTPUT);
- pinMode(M3Lepes, OUTPUT);
- pinMode(M4Irany, OUTPUT);
- pinMode(M4Lepes, OUTPUT);
- pinMode(M5Irany, OUTPUT);
- pinMode(M5Lepes, OUTPUT);
- pinMode(A7,INPUT);
- digitalWrite(M1Lepes,HIGH);
- digitalWrite(M2Lepes,HIGH);
- digitalWrite(M3Lepes,HIGH);
- digitalWrite(M4Lepes,HIGH);
- digitalWrite(M5Lepes,HIGH);
- irrecv.enableIRIn(); // Start the receiver
- Serial.println("Enabled IRin");
- // Serial1.print("AT+VERSION\r\n");
- lcd.setCursor(15,0);
- lcd.print("+");
- digitalWrite(M1AIrany,LOW);
- digitalWrite(M1BIrany,HIGH);
- digitalWrite(M2Irany,LOW);
- digitalWrite(M3Irany,LOW);
- digitalWrite(M4Irany,LOW);
- digitalWrite(M5Irany,LOW);
- lcd.setCursor(0,0);
- lcd.print("Lepes: ");
- lcd.setCursor(7,0);
- lcd.print(lepes);
- }
- void tikkel() {
- //M1clong=2, M1cc=0
- if (M1run==true) { // M1 motor fut-e
- //M1del,M1Delc
- M1delc++; // késleltetés számláló
- if (M1delc==M1del) { // Várakozás vége
- M1delc=0; // késleltetés számláló alaphelyzet
- M1stepOne(); // M1 motor lépés
- M1stepnum--; // Lépés számláló csökkentése
- if (M1stepnum==0) { // Megvolt az összes lépés
- M1commread(); // Következő lépés parancs beolvasása
- }
- }
- }
- if (M2run==true) {
- M2delc++;
- if (M2delc==M2del) { // Várakozás vége
- M2delc=0;
- M2stepOne();
- M2stepnum--; // Lépés számláló csökkentése
- if (M2stepnum==0) { // Megvolt az összes lépés
- M2commread();
- }
- }
- }
- if (M3run==true) {
- M3delc++;
- if (M3delc==M3del) { // Várakozás vége
- M3delc=0;
- M3stepOne();
- M3stepnum--; // Lépés számláló csökkentése
- if (M3stepnum==0) { // Megvolt az összes lépés
- M3commread();
- }
- }
- }
- /*
- if (M4run==true) {
- M4delc++;
- if (M4delc==M4del) { // Várakozás vége
- M4delc=0;
- M4stepOne();
- M4stepnum--; // Lépés számláló csökkentése
- if (M4stepnum==0) { // Megvolt az összes lépés
- M4commread();
- }
- }
- }
- */
- if (M5run==true) {
- M5delc++;
- if (M5delc==M5del) { // Várakozás vége
- M5delc=0;
- M5stepOne();
- M5stepnum--; // Lépés számláló csökkentése
- if (M5stepnum==0) { // Megvolt az összes lépés
- M5commread();
- }
- }
- }
- }
- void M1commread() {
- if (M1cc<M1clong) {
- Serial.print("M1 ");
- Serial.print(M1cc);
- M1dir=M1comm[prg][M1cc++];
- M1del=M1comm[prg][M1cc++];
- M1stepnum=M1comm[prg][M1cc++];
- Serial.print(" ");
- Serial.print(M1dir);
- Serial.print(" ");
- Serial.print(M1del);
- Serial.print(" ");
- Serial.print(M1stepnum);
- Serial.print(" ");
- Serial.println(M1cc);
- } else {
- M1run=false; // Ha a parancs számláló vége, nincs lépés
- Serial.println("M1 STOP");
- }
- }
- void M2commread() {
- if (M2cc<M2clong) {
- Serial.print("M2 ");
- Serial.println(M2cc);
- M2dir=M2comm[prg][M2cc++];
- M2del=M2comm[prg][M2cc++];
- M2stepnum=M2comm[prg][M2cc++];
- } else {
- M2run=false; // Ha a parancs számláló vége, nincs lépés
- Serial.println("M2 STOP");
- }
- }
- void M3commread() {
- if (M3cc<M3clong) {
- Serial.print("M3 ");
- Serial.println(M3cc);
- M3dir=M3comm[prg][M3cc++];
- M3del=M3comm[prg][M3cc++];
- M3stepnum=M3comm[prg][M3cc++];
- } else {
- M3run=false; // Ha a parancs számláló vége, nincs lépés
- Serial.println("M3 STOP");
- }
- }
- void M4commread() {
- if (M4cc<M4clong) {
- Serial.print("M4 ");
- Serial.println(M4cc);
- M4dir=M4comm[prg][M4cc++];
- M4del=M4comm[prg][M4cc++];
- M4stepnum=M4comm[prg][M4cc++];
- } else {
- M4run=false; // Ha a parancs számláló vége, nincs lépés
- Serial.println("M4 STOP");
- }
- }
- void M5commread() {
- if (M5cc<M5clong) {
- Serial.print("M5 ");
- Serial.println(M5cc);
- M5dir=M5comm[prg][M5cc++];
- M5del=M5comm[prg][M5cc++];
- M5stepnum=M5comm[prg][M5cc++];
- } else {
- M5run=false; // Ha a parancs számláló vége, nincs lépés
- Serial.println("M5 STOP");
- }
- }
- void ArmOn() {
- // M1step(260,1);
- M1step(520,1);
- M3step(1240,1);
- M5step(200,0);
- M2step(240,0);
- M4step(50,0);
- }
- void ArmOff() {
- M4step(50,1);
- M2step(240,1);
- M5step(200,1);
- M3step(1240,0);
- M1step(520,0);
- // M1step(260,0);
- }
- void Zeropos() {
- if (M1pos!=0) {
- M1step(abs(M1pos),(M1pos>0));
- }
- if (M3pos!=0) {
- M3step(abs(M3pos),(M3pos>0));
- }
- if (M5pos!=0) {
- M5step(abs(M5pos),(M5pos>0));
- }
- if (M2pos!=0) {
- M2step(abs(M2pos),(M2pos>0));
- }
- if (M4pos!=0) {
- M4step(abs(M4pos),(M4pos>0));
- }
- }
- void M1stepOne() {
- if (M1dir==0) {
- if (M1pos<M1max) {
- M1pos++;
- digitalWrite(M1AIrany,HIGH);
- digitalWrite(M1BIrany,LOW);
- digitalWrite(M1Lepes,LOW);
- delayMicroseconds(10);
- digitalWrite(M1Lepes,HIGH);
- }
- }
- if (M1dir==1) {
- if (M1pos>M1min) {
- M1pos--;
- digitalWrite(M1AIrany,LOW);
- digitalWrite(M1BIrany,HIGH);
- digitalWrite(M1Lepes,LOW);
- delayMicroseconds(10);
- digitalWrite(M1Lepes,HIGH);
- }
- }
- }
- void M2stepOne() {
- if (M2dir==0) {
- if (M2pos<M2max) {
- M2pos++;
- digitalWrite(M2Irany,HIGH);
- digitalWrite(M2Lepes,LOW);
- delayMicroseconds(100);
- digitalWrite(M2Lepes,HIGH);
- }
- }
- if (M2dir==1) {
- if (M2pos>M2min) {
- M2pos--;
- digitalWrite(M2Irany,LOW);
- digitalWrite(M2Lepes,LOW);
- delayMicroseconds(100);
- digitalWrite(M2Lepes,HIGH);
- }
- }
- }
- void M3stepOne() {
- if (M3dir==0) {
- if (M3pos<M3max) {
- M3pos++;
- digitalWrite(M3Irany,HIGH);
- digitalWrite(M3Lepes,LOW);
- delayMicroseconds(100);
- digitalWrite(M3Lepes,HIGH);
- }
- }
- if (M3dir==1) {
- if (M3pos>M3min) {
- M3pos--;
- digitalWrite(M3Irany,LOW);
- digitalWrite(M3Lepes,LOW);
- delayMicroseconds(100);
- digitalWrite(M3Lepes,HIGH);
- }
- }
- }
- void M4stepOne() {
- if (M4dir==0) {
- if (M4pos<M4max) {
- M4pos++;
- digitalWrite(M4Irany,HIGH);
- digitalWrite(M4Lepes,LOW);
- delayMicroseconds(100);
- digitalWrite(M4Lepes,HIGH);
- }
- }
- if (M4dir==1) {
- if (M4pos>M4min) {
- M4pos--;
- digitalWrite(M4Irany,LOW);
- digitalWrite(M4Lepes,LOW);
- delayMicroseconds(100);
- digitalWrite(M4Lepes,HIGH);
- }
- }
- }
- void M5stepOne() {
- if (M5dir==0) {
- if (M5pos<M5max) {
- M5pos++;
- digitalWrite(M5Irany,HIGH);
- digitalWrite(M5Lepes,LOW);
- delayMicroseconds(100);
- digitalWrite(M5Lepes,HIGH);
- }
- }
- if (M5dir==1) {
- if (M5pos>M5min) {
- M5pos--;
- digitalWrite(M5Irany,LOW);
- digitalWrite(M5Lepes,LOW);
- delayMicroseconds(100);
- digitalWrite(M5Lepes,HIGH);
- }
- }
- }
- void M1step(int stepnum, bool dir) {
- Serial.print(" M1 dir:");
- Serial.print(dir);
- Serial.print(" pos: ");
- Serial.print(M1pos);
- for (uint16_t i=1;i<=stepnum;i++) {
- if (dir==0) {
- if (M1pos<M1max) {
- M1pos++;
- digitalWrite(M1AIrany,HIGH);
- digitalWrite(M1BIrany,LOW);
- digitalWrite(M1Lepes,LOW);
- delay(5);
- digitalWrite(M1Lepes,HIGH);
- delay(5);
- }
- } else {
- if (M1pos>M1min) {
- M1pos--;
- digitalWrite(M1AIrany,LOW);
- digitalWrite(M1BIrany,HIGH);
- digitalWrite(M1Lepes,LOW);
- delay(5);
- digitalWrite(M1Lepes,HIGH);
- delay(5);
- }
- }
- }
- Serial.print(" ");
- Serial.println(M1pos);
- }
- void M2step(int stepnum, bool dir) {
- Serial.print(" M2 dir:");
- Serial.print(dir);
- Serial.print(" pos: ");
- Serial.print(M2pos);
- for (uint16_t i=1;i<=stepnum;i++) {
- if (dir==0) {
- if (M2pos<M2max) {
- M2pos++;
- digitalWrite(M2Irany,HIGH);
- digitalWrite(M2Lepes,LOW);
- delay(5);
- digitalWrite(M2Lepes,HIGH);
- delay(5);
- }
- } else {
- if (M2pos>M2min) {
- M2pos--;
- digitalWrite(M2Irany,LOW);
- digitalWrite(M2Lepes,LOW);
- delay(5);
- digitalWrite(M2Lepes,HIGH);
- delay(5);
- }
- }
- }
- Serial.print(" ");
- Serial.println(M2pos);
- }
- void M3step(int stepnum, bool dir) {
- Serial.print(" M3 dir:");
- Serial.print(dir);
- Serial.print(" pos: ");
- Serial.print(M3pos);
- for (uint16_t i=1;i<=stepnum;i++) {
- if (dir==0) {
- if (M3pos<M3max) {
- M3pos++;
- digitalWrite(M3Irany,HIGH);
- digitalWrite(M3Lepes,LOW);
- delay(1);
- digitalWrite(M3Lepes,HIGH);
- delay(1);
- }
- } else {
- if (M3pos>M3min) {
- M3pos--;
- digitalWrite(M3Irany,LOW);
- digitalWrite(M3Lepes,LOW);
- delay(1);
- digitalWrite(M3Lepes,HIGH);
- delay(1);
- }
- }
- }
- Serial.print(" ");
- Serial.println(M3pos);
- }
- void M4step(int stepnum, bool dir) {
- Serial.print(" M4 dir:");
- Serial.print(dir);
- Serial.print(" pos: ");
- Serial.print(M4pos);
- for (uint16_t i=1;i<=stepnum;i++) {
- if (dir==0) {
- if (M4pos<M4max) {
- M4pos++;
- digitalWrite(M4Irany,HIGH);
- digitalWrite(M4Lepes,LOW);
- delay(1);
- digitalWrite(M4Lepes,HIGH);
- delay(1);
- }
- } else {
- if (M4pos>M4min) {
- M4pos--;
- digitalWrite(M4Irany,LOW);
- digitalWrite(M4Lepes,LOW);
- delay(1);
- digitalWrite(M4Lepes,HIGH);
- delay(1);
- }
- }
- }
- Serial.print(" ");
- Serial.println(M4pos);
- }
- void M5step(int stepnum, bool dir) {
- Serial.print(" M5 dir:");
- Serial.print(dir);
- Serial.print(" pos: ");
- Serial.print(M5pos);
- for (uint16_t i=1;i<=stepnum;i++) {
- if (dir==0) {
- if (M5pos<M5max) {
- M5pos++;
- digitalWrite(M5Irany,HIGH);
- digitalWrite(M5Lepes,LOW);
- delay(10);
- digitalWrite(M5Lepes,HIGH);
- delay(10);
- }
- } else {
- if (M5pos>M5min) {
- M5pos--;
- digitalWrite(M5Irany,LOW);
- digitalWrite(M5Lepes,LOW);
- delay(10);
- digitalWrite(M5Lepes,HIGH);
- delay(10);
- }
- }
- }
- Serial.print(" ");
- Serial.println(M5pos);
- }
- void loop() {
- byte dataInb;
- t.update();
- if (Serial1.available() > 0) {
- //dataIn = Serial1.readString(); // Read the data as string
- dataInb = Serial1.read(); // Read the data as string
- sbuffer[sbc++]=dataInb;
- if (dataInb==120) {
- if (sbc==2) {
- if (sbuffer[0]==83) {
- Serial.println("Save");
- }
- if (sbuffer[0]==76) {
- Serial.println("Run");
- }
- if (sbuffer[0]==75) {
- Serial.println("Pause");
- }
- if (sbuffer[0]==82) {
- Serial.println("Reset");
- }
- }
- if (sbuffer[0]==77) {
- Serial.print("Motor ");
- Serial.println(sbuffer[1]-48);
- motor=sbuffer[1]-48;
- valuecalc();
- }
- sbc=0;
- }
- }
- if (M1btrun==true) M1btmove();
- if (M2btrun==true) M2btmove();
- if (M3btrun==true) M3btmove();
- if (M4btrun==true) M4btmove();
- if (M5btrun==true) M5btmove();
- if (irrecv.decode(&results)) {
- IRValue=results.value;
- IRkiertekel(IRValue);
- IRgogo(IRcode);
- irrecv.resume(); // Receive the next value
- }
- }
- void valuecalc() {
- uint8_t sz=0,i ;
- for ( i=1;i<=10;i++) {
- if (sbuffer[i]==120 or sbuffer[i]==46) {
- sz=i-1;
- break;
- }
- }
- for (i=2;i<=sz;i++) {
- }
- if (sz==2) {
- value=sbuffer[2]-48;
- }
- if (sz==3) {
- value=(sbuffer[2]-48)*10;
- value=value+sbuffer[3]-48;
- }
- if (sz==4) {
- value=(sbuffer[2]-48)*100;
- value=value+(sbuffer[3]-48)*10;
- value=value+sbuffer[4]-48;
- }
- Serial.print("Value ");
- Serial.println(value);
- if (motor==1) {
- M1btrun=true;
- M1dest=value*10-600;
- }
- if (motor==2) {
- M2btrun=true;
- M2dest=value*10-800;
- }
- if (motor==3) {
- M3btrun=true;
- M3dest=value*10-1400;
- }
- if (motor==4) {
- M4btrun=true;
- M4dest=value-50;
- }
- if (motor==5) {
- M5btrun=true;
- M5dest=value*10-250;
- }
- if (motor==6) {
- myservo.write(value);
- }
- //servopoz();
- }
- void servopoz() {
- for (int i=0;i<=10;i++) {
- digitalWrite(13,HIGH);
- delayMicroseconds(value*1000);
- digitalWrite(13,LOW);
- delay(20);
- }
- }
- void M1btmove() {
- M1dir=0;
- if (M1pos>M1dest) M1dir=1;
- M1stepOne();
- delay(10);
- if (M1pos==M1dest) M1btrun=false;
- }
- void M2btmove() {
- M2dir=0;
- if (M2pos>M2dest) M2dir=1;
- M2stepOne();
- delay(5);
- if (M2pos==M2dest) M2btrun=false;
- }
- void M3btmove() {
- M3dir=0;
- if (M3pos>M3dest) M3dir=1;
- /* Serial.print("M3dest:");
- Serial.print(M3dest);
- Serial.print(" M3pos:");
- Serial.print(M3pos);
- Serial.print(" M3dir:");
- Serial.println(M3dir); */
- M3stepOne();
- delay(5);
- if (M3pos==M3dest) M3btrun=false;
- }
- void M4btmove() {
- M4dir=0;
- if (M4pos>M4dest) M4dir=1;
- M4stepOne();
- delay(10);
- if (M4pos==M4dest) M4btrun=false;
- }
- void M5btmove() {
- M5dir=0;
- if (M5pos>M5dest) M5dir=1;
- M5stepOne();
- delay(5);
- if (M5pos==M5dest) M5btrun=false;
- }
- void IRgogo (byte i) {
- if (i==10) lepes=10;
- if (i==11) lepes=100;
- if (i==12) lepes=200;
- lcd.setCursor(0,0);
- lcd.print("Lepes: ");
- lcd.setCursor(7,0);
- lcd.print(lepes);
- if (i==13) { // balra
- lcd.setCursor(15,0);
- lcd.print("-");
- digitalWrite(M1AIrany,HIGH);
- digitalWrite(M1BIrany,LOW);
- digitalWrite(M2Irany,HIGH);
- digitalWrite(M3Irany,HIGH);
- digitalWrite(M4Irany,HIGH);
- digitalWrite(M5Irany,HIGH);
- }
- if (i==14) { // jobbra
- lcd.setCursor(15,0);
- lcd.print("+");
- digitalWrite(M1AIrany,LOW);
- digitalWrite(M1BIrany,HIGH);
- digitalWrite(M2Irany,LOW);
- digitalWrite(M3Irany,LOW);
- digitalWrite(M4Irany,LOW);
- digitalWrite(M5Irany,LOW);
- }
- if (i==1) M1step(lepes,!digitalRead(M1AIrany));
- if (i==2) M2step(lepes,!digitalRead(M2Irany));
- if (i==3) M3step(lepes,!digitalRead(M3Irany));
- if (i==4) M4step(lepes,!digitalRead(M4Irany));
- if (i==5) M5step(lepes,!digitalRead(M5Irany));
- if (i==15) Zeropos(); // EQ
- if (i==16) { // << Start prg1
- prg=0;
- prgstart();
- }
- if (i==17) { // >> Start prg2
- prg=1;
- prgstart();
- }
- if (i==18) { // >I Start prg3
- prg=2;
- prgstart();
- }
- if (i==19) ArmOff(); // CH-
- if (i==21) ArmOn(); // CH+
- if (i==20) { // CH pozíció törlés
- M1pos=0;
- M2pos=0;
- M3pos=0;
- M4pos=0;
- M5pos=0;
- }
- }
- void prgstart() {
- if (M1run==true or M2run==true or M3run==true or M4run==true or M5run==true ) {
- M1run=false;
- M2run=false;
- M3run=false;
- M4run=false;
- M5run=false;
- Zeropos(); // Alaphelyzetbe állás
- }
- M1cc=0;
- M2cc=0;
- M3cc=0;
- M4cc=0;
- M5cc=0;
- M1commread();
- M2commread();
- M3commread();
- M4commread();
- M5commread();
- M1run=true;
- M2run=true;
- M3run=true;
- //M4run=true;
- M5run=true;
- }
- void IRkiertekel(long i) {
- //Serial.print(i);
- IRcode=0;
- switch(i){
- case 16738455:
- IRcode=10;
- Serial.println("0");
- break;
- case 16753245:
- IRcode=19;
- Serial.println("CH-");
- break;
- case 16736925:
- IRcode=20;
- Serial.println("CH");
- break;
- case 16769565:
- IRcode=21;
- Serial.println("CH+");
- break;
- case 16761405:
- IRcode=18;
- Serial.println(">I");
- break;
- case 16720605:
- IRcode=16;
- Serial.println("<<");
- break;
- case 16712445:
- IRcode=17;
- Serial.println(">>");
- break;
- case 16769055:
- IRcode=13;
- Serial.println("-");
- break;
- case 16754775:
- IRcode=14;
- Serial.println("+");
- break;
- case 16748655:
- IRcode=15;
- Serial.println("EQ");
- break;
- case 16724175: //1
- IRcode=1;
- Serial.println("1");
- break;
- case 16718055: // 2
- IRcode=2;
- Serial.println("2");
- break;
- case 16743045: // 3
- IRcode=3;
- Serial.println("3");
- break;
- case 16716015: // 4
- IRcode=4;
- Serial.println("4");
- break;
- case 16726215: // 5
- IRcode=5;
- Serial.println("5");
- break;
- case 16734885: // 6
- IRcode=6;
- Serial.println("6");
- break;
- case 16728765: // 7
- IRcode=7;
- Serial.println("7");
- break;
- case 16730805: // 8
- IRcode=8;
- Serial.println("8");
- break;
- case 16732845: // 9
- IRcode=9;
- Serial.println("9");
- break;
- case 16750695: // 100+
- IRcode=11;
- Serial.println("100+");
- break;
- case 16756815: // 200+
- IRcode=12;
- Serial.println("200+");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement