I have working code for the thermocouple, and I also have working code for the two motors. I am able to control how many seconds each motor turns and in what direction. However I am trying to use the encoders to tell the motors to tern a certain degree amount in a certain direction. I am having trouble figuring that part out.
#include "max6675.h"
//Thermocouple outputs and inputs
int thermoDO = 19;
int thermoCS = 20;
int thermoCLK = 21;
const int MA1 =15;
// Motor A input 1
const int MA2 =14;
// Motor A input 2
const int MB1 =17;
// Motor B input 1
const int MB2 =16;
// Motor B input 2
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
void setup() {
Serial.begin(9600);
// wait for MAX chip to stabilize
delay(500);
// set pins
pinMode(MA1, OUTPUT);
pinMode(MA2, OUTPUT);
pinMode(MB1, OUTPUT);
pinMode(MB2, OUTPUT);
}
void loop() {
// basic readout test, just print the current temp
Serial.print("C = ");
Serial.println(thermocouple.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple.readFahrenheit());
// For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
delay(1000);
// Turn motor A (forward)
digitalWrite(MA1, HIGH);
digitalWrite(MA2, LOW);
// Turn on Motor B (forward)
digitalWrite(MB1, HIGH);
digitalWrite(MB2, LOW);
delay(2000);
// Run motors for 2 seconds
// Stop both motors
digitalWrite(MA1, LOW);
digitalWrite(MA2, LOW);
digitalWrite(MB1, LOW);
digitalWrite(MB2, LOW);
delay(2000);
// Wait for 5 seconds before repeating
// Turn motor A (reverse)
digitalWrite(MA1, LOW);
digitalWrite(MA2, HIGH);
// Turn on Motor B (reverse)
digitalWrite(MB1, LOW);
digitalWrite(MB2, HIGH);
delay(2000);
// Run motors for 2 seconds
// Stop both motors
digitalWrite(MA1, LOW);
digitalWrite(MA2, LOW);
digitalWrite(MB1, LOW);
digitalWrite(MB2, LOW);
delay(2000);
// Wait for 2 seconds before repeating
}
This is the code I currently have to test that components are working. But I want to be able to use degrees as a increment of motor turning instead of time.