Guest User

Untitled

a guest
Jan 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "TimerOne.h"
  3. int i = 0;
  4. int count = 0;
  5. int lowspeed = 1000;
  6. int MSsteps[5] = {7,6,2,4,0};
  7. void callback1();
  8. void setup()
  9. {
  10.   DDRB = 0xFF; // pin 8 for dir, pin 9 for timer
  11.   DDRD = 0xF4; // pin 2 to 4 are for MS#
  12.   PORTB = 0;   // want MS# to be 0s
  13.   PORTD = 0;   // want dir and timer 0
  14.  
  15.   //pinMode(5, OUTPUT);
  16.   //pinMode(6, OUTPUT);
  17.   //pinMode(2, OUTPUT);
  18.   //pinMode(3, OUTPUT);
  19.   //digitalWrite(3,LOW);
  20.   //digitalWrite(2,HIGH);
  21.   //Timer0.initialize(10000000);
  22.   Timer1.initialize(10000);
  23.   TCCR1A |= _BV(COM1A0);
  24.   TCCR1B |= _BV(WGM12);
  25.   //Timer1.attachInterrupt(callback1);
  26.   Serial.begin(19200);
  27. }
  28. void callback1()
  29. {
  30.   if(count == lowspeed)
  31.   {
  32.     PORTD ^= 0x8;
  33.     count=0;
  34.   }
  35.   else
  36.     count++;
  37. }
  38. void loop()
  39. {
  40.   i = 1;
  41.   //for(i = 0; i <=4; i++)
  42.   {
  43.     PORTD &= 0xE3;    // resets MS# to 0;
  44.     PORTD |= (MSsteps[i] << 2);
  45.     Serial.print("PORTD is ");
  46.     Serial.println(PORTD,BIN);
  47.     delay(5000);
  48.   }
  49. }
Add Comment
Please, Sign In to add comment