Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +/*
- Stepper Motor Control - one revolution
- This program drives a unipolar or bipolar stepper motor.
- The motor is attached to digital pins 8 - 11 of the Arduino.
- The motor should revolve one revolution in one direction, then
- one revolution in the other direction.
- Created 11 Mar. 2007
- Modified 30 Nov. 2009
- by Tom Igoe
- */
- #include <TM1637Display.h>
- const int CLK = 7; //Set the CLK pin connection to the display
- const int DIO = 6; //Set the DIO pin connection to the display
- int sek = 0;
- int ja = 0;
- int tid = 5;
- int tider = 10;
- #include <Stepper.h>
- const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
- // for your motor
- TM1637Display display(CLK, DIO); //set up the 4-Digit Display.
- // initialize the stepper library on pins 8 through 11:
- Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
- void setup() {
- // set the speed at 60 rpm:
- myStepper.setSpeed(60);
- // initialize the serial port:
- Serial.begin(9600);
- display.setBrightness(0x0a); //set the diplay to maximum brightness
- pinMode(3,INPUT_PULLUP); // mere tid
- pinMode(2,INPUT_PULLUP); // mindre tid
- pinMode(5,INPUT_PULLUP); // meget mere tid
- pinMode(4,INPUT_PULLUP); // meget mindre tid
- pinMode(12,INPUT_PULLUP); // start
- pinMode(13,INPUT_PULLUP); // stop
- }
- void loop() {
- Serial.println(sek);
- display.showNumberDec(sek);
- if(digitalRead(3) == LOW){
- sek = sek+tid;
- delay(500);
- }
- else if(digitalRead(2)== LOW){
- sek = sek-tid;
- delay(500);
- }
- else if(digitalRead(5)== LOW){
- sek = sek+tider;
- delay(500);
- }
- if(digitalRead(4)== LOW){
- sek = sek-tider;
- delay(500);
- }
- else if(digitalRead(12)== LOW){
- ja = 1;
- delay(500);
- }
- else if(digitalRead(13) == LOW){
- ja = 0;
- sek = 0;
- delay(500);
- }
- if(sek == 0){
- ja = 0;
- }
- while(sek > 0 && ja == 1){
- Serial.println(sek);
- display.showNumberDec(sek);
- myStepper.step(stepsPerRevolution);
- if(digitalRead(13) == LOW){
- ja = 0;
- }
- sek = sek-1;
- if(sek == 0){
- ja = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement