Differences

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

Link to this comparison view

Next revision
Previous revision
et:arduino:motors:project4 [2016/12/09 08:18] – tekitatud raivo.sellet:arduino:motors:project4 [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Projekt 3 Tahhomeeter samm-mootoriga ======+====== Projekt 3 Analoog näidik samm-mootoriga ====== 
 + 
 + 
 +=== Näide 1 auto tahhomeeter === 
 +\\ 
 + 
 +<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); 
 + 
 +int posArray[] = {0,    800,  0,    800,  0,    800,  1500, 3000, 2000, 1000, 3000}; 
 +int accArray[] = {1000, 3000, 1000, 3000, 1000, 3000, 2000, 2000, 1000, 1000, 3000}; 
 + 
 +void setup() 
 +
 +  Serial.begin(9600); 
 +  stepper1.setMaxSpeed(2000.0); 
 +  stepper1.setAcceleration(10000.0); 
 +  stepper1.setSpeed(100); 
 +
 + 
 +void loop(){ 
 + // pote = analogRead(A0)*6; 
 +  for(int i = 0; i<sizeof(posArray); i++){ 
 +    stepper1.moveTo(posArray[i]); 
 +    stepper1.setAcceleration(accArray[i]); 
 +    while(stepper1.currentPosition() != posArray[i]){ 
 +       stepper1.run(); 
 +    } 
 +  } 
 +
 + 
 +</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>
  
et/arduino/motors/project4.1481271494.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