0% found this document useful (0 votes)
14 views

PASS

The document describes code for controlling a stepper motor using buttons to increase or decrease speed. It defines a sequence array for the motor steps and initializes a speed delay variable. The main loop continually checks if buttons are pressed to adjust speed and then cycles through the step sequence with delays set by the speed variable.

Uploaded by

mouzounasamir2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

PASS

The document describes code for controlling a stepper motor using buttons to increase or decrease speed. It defines a sequence array for the motor steps and initializes a speed delay variable. The main loop continually checks if buttons are pressed to adjust speed and then cycles through the step sequence with delays set by the speed variable.

Uploaded by

mouzounasamir2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Define the sequence of steps for the stepper motor (adjust for your specific motor)

unsigned char sequence[] = {0b00000001, 0b00000010, 0b00000100, 0b00001000};

int speedDelay = 10; // Initial delay for motor speed control

void main() {

TRISB = 0x00; // Configure all the pins of port B as outputs

TRISA.F0 = 1; // Configure RA0 (button for speeding up) as input

TRISA.F1 = 1; // Configure RA1 (button for slowing down) as input

int i;

while (1) {

// Check if the speeding up button is pressed

if (PORTA.F0 == 0) {

speedDelay -= 5; // Reduce delay to increase speed (adjust as needed)

if (speedDelay < 5) {

speedDelay = 5; // Minimum speed delay to prevent too fast motor rotation

while (PORTA.F0 == 0); // Wait for button release

// Check if the slowing down button is pressed

if (PORTA.F1 == 0) {

speedDelay += 5; // Increase delay to decrease speed (adjust as needed)

if (speedDelay > 100) {

speedDelay = 100; // Maximum speed delay to prevent too slow motor rotation

while (PORTA.F1 == 0); // Wait for button release

}
for (i = 0; i < 4; i++) {

PORTB = sequence[i]; // Activate the step sequence

// Add a delay to control the motor speed

Delay_ms(speedDelay);

You might also like