117
edits
No edit summary |
No edit summary |
||
Line 103: | Line 103: | ||
== Code-Motor == | == Code-Motor == | ||
int one_cycle_step_count = 6; | |||
int one_motorrotation_cycle_count = 8; | |||
float gear_factor = 16.375; | |||
float one_gearrotation_cycle_count = gear_factor * one_motorrotation_cycle_count; | |||
float one_gearrotation_step_count = one_gearrotation_cycle_count * one_cycle_step_count; | |||
int full_track_minutes = 0; | |||
float rest_track_seconds = 5; | |||
float track_length_in_seconds = full_track_minutes * 60 + rest_track_seconds; | |||
float track_length_in_milliseconds = track_length_in_seconds * 1000; | |||
float motor_power_time_in_mikroseconds = track_length_in_milliseconds / (one_gearrotation_cycle_count * one_cycle_step_count) * 1000; | |||
short i = 0; | |||
bool break_ = true; // "Bremse": Bei schneller Drehung dreht der Motor nach, sobald keine Spannung mehr anliegt. Die Bremse soll dies verhindern. | |||
void setup() { | |||
pinMode(2, OUTPUT); | |||
pinMode(3, OUTPUT); | |||
pinMode(4, OUTPUT); | |||
pinMode(5, OUTPUT); | |||
pinMode(6, OUTPUT); | |||
pinMode(7, OUTPUT); | |||
Serial.begin(9600); | |||
digitalWrite(2, LOW); | |||
digitalWrite(3, LOW); | |||
digitalWrite(4, LOW); | |||
digitalWrite(5, LOW); | |||
digitalWrite(6, LOW); | |||
digitalWrite(7, LOW); | |||
Serial.println("motor_power_time"); | |||
Serial.println(motor_power_time_in_mikroseconds); | |||
Serial.println("track_length_in_milliseconds"); | |||
Serial.println(track_length_in_milliseconds); | |||
Serial.println("one_gearrotation_cycle_count"); | |||
Serial.println(one_gearrotation_cycle_count); | |||
Serial.println("one_cycle_step_count"); | |||
Serial.println(one_cycle_step_count); | |||
Serial.println("one_gearrotation_cycle_count"); | |||
Serial.println(one_gearrotation_cycle_count); | |||
Serial.println("one_gearrotation_cycle_count"); | |||
Serial.println(motor_power_time_in_mikroseconds); | |||
} | |||
void loop() { | |||
while(i < one_gearrotation_cycle_count) | |||
{ | |||
digitalWrite(3, HIGH); | |||
digitalWrite(4, HIGH); | |||
delayMicroseconds(motor_power_time_in_mikroseconds); | |||
digitalWrite(4, LOW); | |||
digitalWrite(6, HIGH); | |||
delayMicroseconds(motor_power_time_in_mikroseconds); | |||
digitalWrite(3, LOW); | |||
digitalWrite(5, HIGH); | |||
delayMicroseconds(motor_power_time_in_mikroseconds); | |||
digitalWrite(6, LOW); | |||
digitalWrite(2, HIGH); | |||
delayMicroseconds(motor_power_time_in_mikroseconds); | |||
digitalWrite(5, LOW); | |||
digitalWrite(7, HIGH); | |||
delayMicroseconds(motor_power_time_in_mikroseconds); | |||
digitalWrite(2, LOW); | |||
digitalWrite(4, HIGH); | |||
delayMicroseconds(motor_power_time_in_mikroseconds); | |||
digitalWrite(7, LOW); | |||
i++; | |||
} | |||
if(break_ == true) //Halte den Motor um ein ausrollen zu verhindern. | |||
{ | |||
digitalWrite(3, HIGH); | |||
digitalWrite(4, HIGH); | |||
delay(100); | |||
break_ = false; //Deaktiviere die Bremse | |||
} | |||
digitalWrite(3, LOW); | |||
digitalWrite(4, LOW); | |||
} | |||
== Medium == | == Medium == |
edits