"""
Made by Jefferson Sandoval for the Interface and Application Programming during the 
FabAcademy2021
  
This is a simple code in Python to test an interface made with Tkinter to control a DC motor 
controller board.

Documentation:
http://fabacademy.org/2021/labs/kamplintfort/students/jefferson-sandoval/assignments/week15/

Board documentation:
http://fabacademy.org/2021/labs/kamplintfort/students/jefferson-sandoval/assignments/week13/
"""

#Import libraries
import serial
import tkinter

#Start serial communication with board
arduinoData = serial.Serial('COM3', 9600)

#Define functions
def cw_rotation():
    arduinoData.write(b'1')

def ccw_rotation():
    arduinoData.write(b'2')

def off():
    arduinoData.write(b'0')

#Create window
led_control_window = tkinter.Tk()
led_control_window.title("DC motor controller App V1.0")

#Create buttons
button = tkinter.Button

btn1 = button(led_control_window, text="CW rotation", font='Roboto 11 bold', bg="SteelBlue1", width="11", height="3", command=cw_rotation)
btn1.pack(side='left', padx=15, pady=20)

btn2 = button(led_control_window, text="CCW rotation", font='Roboto 11 bold', bg="DarkOliveGreen1", width="11", height="3", command=ccw_rotation)
btn2.pack(side='left', padx=15, pady=20)

btn3 = button(led_control_window, text="Turn off", font='Roboto 11 bold', bg="tomato2", width="11", height="3", command=off)
btn3.pack(side='left', padx=15, pady=20)

led_control_window.mainloop()
