hello,
visited this forum after sometime. I changed from UNO to Mega and my robot head is
going haywire. what needs to be done?.
I presume the code has nothing to do with this change - so I am skeptical to change the code.
I use stepper commands, copied form another sketch which worked beautifully on UNO with smooth movement of head. I am not following 100% the code either as I could not find any explanation on commands/instructions. INT in UNO is 32 bit and on Mega its 64. if the code needs to be changed
let me know.
any leads please?
sunil vijaya
code below
#include <Stepper.h>
//motor head move
int step_mode = 4;
int stepsPerRevolution = 4096 * (step_mode / 4) ;
int mysteps = 1 * stepsPerRevolution;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11, step_mode);
int coords[] = { -512, 1024, 256, -2048, 512, 256};
// when laser beam cut off sound alarm
int sensorPin = A0;
int sensorValue = 0;
int laserPin = 3; // laser beam
int buzzer = 2 ;
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(10);
// initialize the serial port:
Serial.begin(9600);
// to sound buzzer if laser beam is cut off
pinMode (sensorPin, INPUT);
pinMode (buzzer, OUTPUT) ;//
pinMode (laserPin, OUTPUT);
// pinMode(5, INPUT_PULLUP); //Button 4 with internal pull up
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(mysteps);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-mysteps);
delay(500);
// 2nd Example -> motor steps to the named points in the coords array
int i;
for (i = 0; i < 6; i++) {
int point = coords;
Serial.println("Next point ");
Serial.println(point);
myStepper.step(point);
delay(500);
}
//---------------------------------------------------------------------
// sound buzzer if laser beam is cut off
// sensorValue=analogRead(sensorPin);
// if(sensorValue<=1000) {digitalWrite(buzzer,HIGH);}
noTone(11);
tone(buzzer, 440, 200); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(6);
tone(buzzer, 494, 500); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(7);
tone(buzzer, 523, 300);
delay(100);
digitalWrite (laserPin, HIGH); // Turn Laser On
delay (500); // On For Half a Second
noTone(11);
tone(buzzer, 440, 200); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(6);
tone(buzzer, 494, 1000); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
// else {digitalWrite(buzzer,LOW); }
// sensorValue=1000;
}