Zitat:
#include <LiquidCrystal.h>
#include <AccelStepper.h>
#include <Wire.h>
#define ANALOG_IN0 A0
#define ANALOG_IN1 A1
#define ANALOG_IN2 A2
#define ANALOG_IN3 A3
LiquidCrystal lcd(34, 36, 38, 40, 42, 44, 46, 48, 50, 52);
AccelStepper stepper0(1, 13, 12); //Stepper 1
AccelStepper stepper1(1, 7, 6); //Stepper 2
AccelStepper stepper2(1, 10, 9); //Stepper 3
AccelStepper stepper3(1, 4, 3); //Stepper 4
const int inputPin_0 = 53; // Input Pin 43 Menü Teachen-Modus
const int inputPin_1 = 51; // Input Pin 45 Menü Automatik-Modus
const int inputPin_2 = 49; // Input Pin 47 Menü Justage-Modus
volatile int state=0; // Variablen, die von Interruptroutinen angefasst werden, sollten "volatile" deklariert werden
volatile unsigned long lastTime=0; // Zeitpunkt der letzten steigenden Flanke, nötig zum Entprellen
const int x = 0;
const int y = 0;
const int z = 0;
const int Wahl= 0;
const int Speed= 0;
const int Delay= 0;
const int Tool= 0;
const int Pos = 1;
void setup()
{
Wire.begin();
stepper0.setMaxSpeed(10000);
stepper0.setAcceleration(10000);
stepper1.setMaxSpeed(10000);
stepper1.setAcceleration(10000);
stepper2.setMaxSpeed(10000);
stepper2.setAcceleration(10000);
stepper3.setMaxSpeed(10000);
stepper3.setAcceleration(10000);
pinMode(inputPin_0, INPUT); // Input Deklaration
pinMode(inputPin_1, INPUT); // Input Deklaration
pinMode(inputPin_2, INPUT); // Input Deklaration
attachInterrupt(49, KeyPressed_1, RISING); // 43 ist der Interrupt , bei jeder steigenden Flanke wird keyPressed_0() aufgerufen
attachInterrupt(51, KeyPressed_2, RISING); // 45 ist der Interrupt , bei jeder steigenden Flanke wird keyPressed_1() aufgerufen
attachInterrupt(53, KeyPressed_3, RISING); // 47 ist der Interrupt , bei jeder steigenden Flanke wird keyPressed_2() aufgerufen
lcd.begin(16,4); // 1 ist der Interrupt für Pin 2, bei jeder steigenden Flanke wird keyPressed_1() aufgerufen
}
//.........................Interruput Auswertung mit entprellen........................................ .......................//
void KeyPressed_1(){ // state =0 , falls mindestens 100ms seit der letzten Flanke vergangen sind
unsigned long now = millis();
if (now - lastTime > 100){ // entprellen
state=1 ;
}
lastTime=now;
}
void KeyPressed_2(){ // state =1 , falls mindestens 100ms seit der letzten Flanke vergangen sind
unsigned long now = millis();
if (now - lastTime > 100){ // entprellen
state=2 ;
}
lastTime=now;
}
void KeyPressed_3(){ // state = 2 , falls mindestens 100ms seit der letzten Flanke vergangen sind
unsigned long now = millis();
if (now - lastTime > 100){ // entprellen
state=3 ;
}
lastTime=now;
}
//..................................MENÜ............ .................................................. ......................//
void loop()
{
switch(state)
{
case 0:
{ lcd.clear();
lcd.setCursor(0,0) ;
lcd.print(">>>>>>>Robotik<<<<<<") ;
lcd.setCursor(0,1) ;
lcd.print("Projektarbeit2014 by") ;
lcd.setCursor(0,2) ;
lcd.print("Kevin Krause") ;
lcd.setCursor(0,3) ;
lcd.print("Dominik Loher") ;
delay(10000);
state=1;
}
case 1: Teachen_menue();
Joystick();
break;
case 2: Automatik();
break;
case 3: Justage();
break;
}
}
Display:
Zitat:
void Teachen_menue() //Menü Teachen, Display Ausgabe
{ lcd.clear();
lcd.setCursor(0,0) ;
lcd.print("---Teaching-Modus---") ;
lcd.setCursor(0,1) ;
lcd.print( "x=") ; lcd.print(x) ;
lcd.setCursor(7,1) ;
lcd.print( "y=") ; lcd.print(y) ;
lcd.setCursor(14,1) ;
lcd.print( "z=") ; lcd.print(z) ;
lcd.setCursor(0,2) ;
lcd.print( "Speed=") ; lcd.print(Speed) ;
lcd.setCursor(10,2);
lcd.print( "Delay=") ; lcd.print(Delay) ;
lcd.setCursor(0,3);
lcd.print( "Tool=") ; lcd.print(Tool) ;
lcd.setCursor(10,3);
lcd.print( "Pos=") ; lcd.print(Pos) ;
delay(500);
}
void Automatik() //Menü Automatik, Display Ausgabe
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print("--Automatik-Modus--");
lcd.setCursor(0,1);
lcd.print( "x=") ; lcd.print(x) ;
lcd.setCursor(7,1);
lcd.print( "y=") ; lcd.print(y) ;
lcd.setCursor(14,1);
lcd.print( "z=") ; lcd.print(z) ;
lcd.setCursor(0,2);
lcd.print( "Speed=") ; lcd.print(Speed) ;
lcd.setCursor(10,2);
lcd.print( "Delay=") ; lcd.print(Delay) ;
lcd.setCursor(0,3);
lcd.print( "Tool=") ; lcd.print(Tool) ;
lcd.setCursor(10,3);
lcd.print( "Pos=") ; lcd.print(Pos) ;
delay(500);
}
void Justage() //Menü Justage, Display Ausgabe
{ lcd.clear();
lcd.setCursor(0,0);
lcd.print("---Justage-Modus---");
lcd.setCursor(0,1);
lcd.print( "x=") ; lcd.print(x) ;
lcd.setCursor(7,1);
lcd.print( "y=") ; lcd.print(y) ;
lcd.setCursor(14,1);
lcd.print( "z=") ; lcd.print(z) ;
delay(500);
}
joystick:
Zitat:
void Joystick()
{
int analog_in0 = (512 - analogRead(ANALOG_IN0));
int analog_in1 = (512 - analogRead(ANALOG_IN1));
int analog_in2 = (512 - analogRead(ANALOG_IN2));
int analog_in3 = (512 - analogRead(ANALOG_IN3));
int AN0, AN01;
int AN1, AN11;
int AN2, AN21;
int AN3, AN31;
//.......Stepper1..........//
if (analog_in0 >= 35 )
{
AN0 = exp(analog_in0 / 67);
stepper0.setSpeed(AN0) ;
stepper0.runSpeed();
}
else if (analog_in0 <= -35)
{
AN01 = exp(-analog_in0 / 67);
stepper0.setSpeed(-AN01) ;
stepper0.runSpeed();
}
//........Stepper2...........//
else if (analog_in1 >= 35 )
{
AN1 = exp(analog_in1 / 67 );
stepper1.setSpeed(AN1) ;
stepper1.runSpeed();
}
else if (analog_in1 <= -35)
{
AN11 = exp(-analog_in1 / 67 );
stepper1.setSpeed(-AN11) ;
stepper1.runSpeed();
}
//..........Stepper3..........//
else if (analog_in2 >= 35)
{
AN2 = exp (analog_in2 / 67);
stepper2.setSpeed(AN2) ;
stepper2.runSpeed();
}
else if (analog_in2 <= -35)
{
AN21 = exp (-analog_in2 / 67);
stepper2.setSpeed(-AN21) ;
stepper2.runSpeed();
}
//............Stepper4...........//
else if (analog_in3 >= 35 )
{
AN3 = exp (analog_in3 / 67);
stepper3.setSpeed(AN3) ;
stepper3.runSpeed();
}
else if (analog_in3 <= -35)
{
AN31 = exp (-analog_in3 / 67 );
stepper3.setSpeed(-AN31) ;
stepper3.runSpeed();
}
Serial.print( analog_in0 ); Serial.print( ' ' );
Serial.print( analog_in1 ); Serial.print( ' ' );
Serial.print( analog_in2 ); Serial.print( ' ' );
Serial.print( analog_in3 ); Serial.println( "" );
}