/* Made by Jefferson Sandoval for the Interface and Application Programming during the * FabAcademy2021 * * This is a simple code in Arduino for to test an interface made with Tkinter to control a * DC motor controller board. * * This code was uploaded to a board with an Attiny1614 microcontroller. 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/ */ const int motorPin1 = 0; //Pin 1 for motor const int motorPin2 = 1; //Pin 2 for motor const int Enable = 2; //Enable pin of motor int speed=255; //Speed for motor (100%) char serialData; //Variable to read the data void setup() { Serial.begin(9600); //Start serial communication pinMode(motorPin1, OUTPUT); //Set pin1 as output pinMode(motorPin2, OUTPUT); //Set pin2 as output pinMode(Enable, OUTPUT); //Set Enable pin as output digitalWrite(Enable, 1); //Enable the motor } void loop(){ if(Serial.available()>0){ serialData = Serial.read(); //Read incoming data and assign it to serialData variable //if incoming data is "1", rotate motor on ClockWise direction if(serialData == '1'){ analogWrite(motorPin1, speed); analogWrite(motorPin2, 0);} //if incoming data is "2", rotate motor on CounterClockWise direction if(serialData == '2'){ analogWrite(motorPin1, 0); analogWrite(motorPin2, speed);} //if incoming data is "0", Turn off the motor if(serialData == '0'){ analogWrite(motorPin1, 0); analogWrite(motorPin2, 0);} } }