Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
et:arduino:motors:project4 [2017/01/05 12:03] kaupo.raidet:arduino:motors:project4 [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
  
-=== Näide 1 === +=== Näide 1 auto tahhomeeter === 
 +\\
  
 <code c> <code c>
 +
 +
 /* Description /* Description
  
Line 22: Line 24:
 AccelStepper stepper1(8, motorPin1, motorPin3, motorPin2, motorPin4); AccelStepper stepper1(8, motorPin1, motorPin3, motorPin2, motorPin4);
  
-int posArray[] = {0,    800,  0,  800,  0, 800, 1500, 3000, 2000, 1000, 3000, 0, 400, 0, 3000, 0}; +int posArray[] = {0,    800,  0,    800,  0,    800,  1500, 3000, 2000, 1000, 3000}; 
-int accArray[] = {1000, 3000, 1000, 3000, 1000, 3000, 2000, 2000, 500, 1000, 3000, 1000, 3000, 1000, 10000, 1000};+int accArray[] = {1000, 3000, 1000, 3000, 1000, 3000, 2000, 2000, 1000, 1000, 3000};
  
 void setup() void setup()
Line 44: Line 46:
 } }
  
 +</code>
 +
 +
 +\\
 +=== Näide 2 Ajavõtusüsteem (0-60s) ===
 +\\
 +
 +<code c>
 +/* Description
 + 
 + 
 +*/
 + 
 +#include <AccelStepper.h>
 +
 +#define motorPin1  8     // Blue   - 28BYJ48 pin 1
 +#define motorPin2  9     // Pink   - 28BYJ48 pin 2
 +#define motorPin3  10    // Yellow - 28BYJ48 pin 3
 +#define motorPin4  11    // Orange - 28BYJ48 pin 4
 +                        // Red    - 28BYJ48 pin 5 (VCC)
 + 
 +// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
 +AccelStepper stepper1(8, motorPin1, motorPin3, motorPin2, motorPin4);
 +
 +unsigned long startTime, timeSpent = 0;
 + 
 +void setup()
 +{
 +  Serial.begin(9600);
 +
 +  pinMode(A0, INPUT);
 +  digitalWrite(A0, HIGH);
 +  pinMode(5,OUTPUT);
 +  digitalWrite(5,HIGH);
 +  
 +  stepper1.setMaxSpeed(1500);
 +  stepper1.setAcceleration(1000.0);
 +  stepper1.setSpeed(68.266666667);
 +  stepper1.stop();
 +}
 + 
 +void loop(){
 +  
 +  if(digitalRead(A0) == LOW){
 +    beep();
 +    stepper1.moveTo(4096);
 +    stepper1.setSpeed(68.266666667);
 +    startTime = millis();
 +    while(stepper1.currentPosition() < 4096){
 +      if(digitalRead(A0) == LOW && (millis()-startTime) > 1000){
 +        stepper1.stop();
 +        timeSpent = millis() - startTime;
 +        beep();
 +        break;
 +      }
 +    stepper1.runSpeed();
 +    }
 +    if(stepper1.currentPosition() >= 4096){beep(); timeSpent = 60000; stepper1.setCurrentPosition(0);}
 +    Serial.print("Time: ");
 +    Serial.print(timeSpent);
 +    timeSpent = 0;
 +    stepper1.moveTo(0);
 +    stepper1.setSpeed(1500);
 +    delay(500);
 +    while(digitalRead(A0) == HIGH && stepper1.currentPosition() != 0);
 +    beep();
 +    while(stepper1.currentPosition() > 0)stepper1.run();
 +    stepper1.stop();
 +    delay(500);
 +  }
 +}
 +
 +void beep(){
 +  
 +  //tone(5, 500, 100);
 +  digitalWrite(5,LOW);
 +  delay(50);
 +  digitalWrite(5,HIGH);
 +}
  
 </code> </code>
 +
et/arduino/motors/project4.1483617804.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0