mirror of
https://github.com/LinoSchmidt/RoboterArm.git
synced 2026-03-21 02:31:16 +01:00
added button
This commit is contained in:
@@ -2,8 +2,6 @@
|
|||||||
#include <Servo.h>
|
#include <Servo.h>
|
||||||
|
|
||||||
|
|
||||||
#define Debug true //----------------------------------Ausschalten Wichtig! (Nur für testzwecke)---------------------------------------
|
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
//--------------------------> Einstellungen <-----------------------
|
//--------------------------> Einstellungen <-----------------------
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
@@ -30,11 +28,11 @@
|
|||||||
#define Oberarm_Start 111
|
#define Oberarm_Start 111
|
||||||
#define Hand_Start 0
|
#define Hand_Start 0
|
||||||
|
|
||||||
|
|
||||||
#define joystick_LX_Pin 0
|
#define joystick_LX_Pin 0
|
||||||
#define joystick_LY_Pin 1
|
#define joystick_LY_Pin 1
|
||||||
#define joystick_RX_Pin 2
|
#define joystick_RX_Pin 2
|
||||||
#define joystick_RY_Pin 3
|
#define joystick_RY_Pin 3
|
||||||
|
#define joystick_button_Pin 8
|
||||||
|
|
||||||
#define joystick_LX_middle 511
|
#define joystick_LX_middle 511
|
||||||
#define joystick_LY_middle 511
|
#define joystick_LY_middle 511
|
||||||
@@ -49,7 +47,6 @@
|
|||||||
#define joystick_MinSpeed 1
|
#define joystick_MinSpeed 1
|
||||||
|
|
||||||
#define LoopTime 25
|
#define LoopTime 25
|
||||||
|
|
||||||
#define TimeToAutoplay 500
|
#define TimeToAutoplay 500
|
||||||
#define TimeToDetach 80
|
#define TimeToDetach 80
|
||||||
|
|
||||||
@@ -57,6 +54,7 @@
|
|||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
Servo Drehung, Arm, Oberarm, Hand;
|
Servo Drehung, Arm, Oberarm, Hand;
|
||||||
|
|
||||||
int joystick_LX, joystick_LY, joystick_RX, joystick_RY;
|
int joystick_LX, joystick_LY, joystick_RX, joystick_RY;
|
||||||
@@ -65,8 +63,60 @@ int DrehungPos = Drehung_Start, ArmPos = Arm_Start, OberarmPos = Oberarm_Start,
|
|||||||
int offtime = 0;
|
int offtime = 0;
|
||||||
bool detached = true;
|
bool detached = true;
|
||||||
|
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
if(Debug)Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
pinMode(joystick_button_Pin, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void joystickButtonPress(){
|
||||||
|
int Code[5] = {0 ,0 ,0 ,0 ,0}; //0 = short, 1 = long
|
||||||
|
int CodeLenght = 0;
|
||||||
|
bool Finished = false;
|
||||||
|
bool abort = false;
|
||||||
|
|
||||||
|
while(!Finished && !abort){
|
||||||
|
if(CodeLenght > 5)abort = true;
|
||||||
|
|
||||||
|
int buttonTime = 0;
|
||||||
|
while(digitalRead(joystick_button_Pin) == HIGH){
|
||||||
|
buttonTime+= 10;
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buttonTime < 250){
|
||||||
|
Code[CodeLenght] = 0;
|
||||||
|
Serial.println("short press");
|
||||||
|
}
|
||||||
|
else if(buttonTime < 1000){
|
||||||
|
Code[CodeLenght] = 1;
|
||||||
|
Serial.println("long press");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
abort = true;
|
||||||
|
Serial.println("Code aborted!");
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeLenght++;
|
||||||
|
|
||||||
|
buttonTime = 0;
|
||||||
|
while(digitalRead(joystick_button_Pin) == LOW && !Finished && !abort){
|
||||||
|
buttonTime+= 10;
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
if(buttonTime >= 1000){
|
||||||
|
Finished = true;
|
||||||
|
Serial.println("Code fineshed!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!abort){
|
||||||
|
if(Code == && CodeLenght == 1){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int joystick_position(int joystick, int joystick_middle, int joystick_min, int joystick_max){
|
int joystick_position(int joystick, int joystick_middle, int joystick_min, int joystick_max){
|
||||||
@@ -134,7 +184,9 @@ void loop(){
|
|||||||
detached = true;
|
detached = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Debug)Serial.println(String(offtime) + "," + String(DrehungPos) + "," + String(ArmPos) + "," + String(OberarmPos) + "," + String(HandPos));
|
if(digitalRead(joystick_button_Pin) == HIGH)joystickButtonPress();
|
||||||
|
|
||||||
|
Serial.println(String(offtime) + "," + String(DrehungPos) + "," + String(ArmPos) + "," + String(OberarmPos) + "," + String(HandPos));
|
||||||
|
|
||||||
delay(LoopTime);
|
delay(LoopTime);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user