from a4988 import A4988
from morse import MorseCode
from mPU6050 import MPU6050
from machine import I2C, Pin
import time
from sSD1306 import SSD1306
# Example usage
if __name__ == "__main__":
# Initialize the A4988 driver
stepper = A4988(step_pin=0, dir_pin=2, ms1_pin=4, ms2_pin=16, ms3_pin=5)
# Set microstepping mode (0 for full step, 1 for half step, 2 for quarter step, etc.)
stepper.set_microstepping(0b001) # Half step
# Set direction (0 for one direction, 1 for the other)
stepper.set_direction(0)
# Move the motor 200 steps
stepper.step(200, delay=0.005) # Adjust delay for speed
# Initialize Morse code
morse = MorseCode(led_pin=19) # Change the pin number as needed
morse.send_message("SOS") # Sends the Morse code for SOS
# Initialize I2C for the OLED display
i2c = I2C(1, scl=Pin(26), sda=Pin(25)) # Adjust pins as needed
oled = SSD1306(128, 64, i2c)
# Initialize MPU6050
mpu = MPU6050(i2c) # Make sure to pass the I2C instance to the MPU6050
oled.fill(0) # Clear the display
oled.pixel(10, 10, 1) # Draw a pixel
oled.show() # Update the display
while True:
# Get acceleration and gyroscope data
acceleration = mpu.get_acceleration()
gyroscope = mpu.get_gyroscope()
# Clear the display
oled.fill(0)
# Display acceleration values in m/s²
oled.text("Acceleration:", 0, 0)
oled.text("X: {0:.2f} m/s²".format(acceleration[0]), 0, 10)
oled.text("Y: {0:.2f} m/s²".format(acceleration[1]), 0, 20)
oled.text("Z: {0:.2f} m/s²".format(acceleration[2]), 0, 30)
# Display gyroscope values
oled.text("Gyroscope:", 0, 40)
oled.text("X: {0} dps".format(gyroscope[0]), 0, 50)
oled.text("Y: {0} dps".format(gyroscope[1]), 0, 60)
oled.text("Z: {0} dps".format(gyroscope[2]), 0, 70)
# Update the display
oled.show()
time.sleep(1)