MalharD:
Can you post the whole arduino code ?
This is my code
// MOTORES
#define Blue_STEP_PIN 54
#define Blue_DIR_PIN 55
#define Blue_ENABLE_PIN 38
#define Yellow_STEP_PIN 60
#define Yellow_DIR_PIN 61
#define Yellow_ENABLE_PIN 56
#define White_STEP_PIN 46
#define White_DIR_PIN 48
#define White_ENABLE_PIN 62
#define Black_STEP_PIN 26
#define Black_DIR_PIN 28
#define Black_ENABLE_PIN 24
#define Red_STEP_PIN 36
#define Red_DIR_PIN 34
#define Red_ENABLE_PIN 30
//Cartucho de Aquecimento
#define HEATER_0_PIN 9
//THERMISTOR NTC 3650 100KOhm
#define TEMP_0_PIN 13
#define THERMISTORNOMINAL 95000 //temperatura
#define TEMPERATURENOMINAL 25 //temperatura
#define NUMSAMPLES 5 //temperatura
#define BCOEFFICIENT 4000 //temperatura
#define SERIESRESISTOR 4700 //temperatura
int samples[NUMSAMPLES]; //temperatura
//Ventoinha
#define FAN_PIN 10
//Potenciometros
#define Blue_Pot 12
#define Yellow_Pot 4
#define White_Pot 5
#define Black_Pot 3
#define Red_Pot 11
//Distancia do filamento
int Blue_dist = 0;
int Yellow_dist = 0;
int White_dist = 0;
int Black_dist = 0;
int Red_dist = 0;
//Direcao dada pelos poteciometros
int Blue_dir = 0;
int Yellow_dir = 0;
int White_dir = 0;
int Black_dir = 0;
int Red_dir = 0;
//Velocidade dos motores
int Blue_Vel = 0;
int Yellow_Vel = 0;
int White_Vel = 0;
int Black_Vel = 0;
int Red_Vel = 0;
//Codigo em separado
unsigned long currentmillis = 0;
unsigned long previousmillis_Blue = 0;
unsigned long previousmillis_Yellow = 0;
unsigned long previousmillis_White = 0;
unsigned long previousmillis_Black = 0;
unsigned long previousmillis_Red = 0;
unsigned long previousmillis_temp = 0;
unsigned long print_temp = 1000000;
void setup() {
pinMode(TEMP_0_PIN , INPUT);
//pinMode(TEMP_1_PIN,INPUT);
//pinMode(TEMP_2_PIN,INPUT);
//analogReference(EXTERNAL); //temperatura
pinMode(FAN_PIN , OUTPUT);
digitalWrite(FAN_PIN, HIGH);
pinMode(HEATER_0_PIN , OUTPUT);
//pinMode(HEATER_1_PIN,OUTPUT);
//pinMode(LED_PIN,OUTPUT);
pinMode(Blue_STEP_PIN , OUTPUT);
pinMode(Blue_DIR_PIN , OUTPUT);
pinMode(Blue_ENABLE_PIN , OUTPUT);
pinMode(Yellow_STEP_PIN , OUTPUT);
pinMode(Yellow_DIR_PIN , OUTPUT);
pinMode(Yellow_ENABLE_PIN , OUTPUT);
pinMode(White_STEP_PIN , OUTPUT);
pinMode(White_DIR_PIN , OUTPUT);
pinMode(White_ENABLE_PIN , OUTPUT);
pinMode(Black_STEP_PIN , OUTPUT);
pinMode(Black_DIR_PIN , OUTPUT);
pinMode(Black_ENABLE_PIN , OUTPUT);
pinMode(Red_STEP_PIN , OUTPUT);
pinMode(Red_DIR_PIN , OUTPUT);
pinMode(Red_ENABLE_PIN , OUTPUT);
digitalWrite(Blue_ENABLE_PIN , LOW);
digitalWrite(Yellow_ENABLE_PIN , LOW);
digitalWrite(White_ENABLE_PIN , LOW);
digitalWrite(Black_ENABLE_PIN , LOW);
digitalWrite(Red_ENABLE_PIN , LOW);
pinMode(Blue_Pot , INPUT);
pinMode(Yellow_Pot , INPUT);
pinMode(White_Pot , INPUT);
pinMode(Black_Pot , INPUT);
pinMode(Red_Pot , INPUT);
Serial.begin(250000);
}
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 1000; // interval at which to blink (milliseconds)
void loop () {
unsigned long currentMillis = micros();
if ((unsigned long)(currentMillis - previousmillis_Blue) >= Blue_Vel) {
Blue_dir = (analogRead(Blue_Pot));
if (Blue_dir <= 500) {
Blue_Vel=10000;
//Blue_Vel = (10 + (Blue_dir * 30)); //empurrar
}
if (Blue_dir > 500) {
Blue_Vel = (((analogRead(Blue_Pot)) * 10) - 5000); //puxar
}
previousmillis_Blue = currentMillis;
if (Blue_dir <= 475) {
digitalWrite(Blue_DIR_PIN, HIGH);
digitalWrite(Blue_STEP_PIN , HIGH);
digitalWrite(Blue_STEP_PIN , LOW);
//Serial.println(Blue_dir);
//Serial.println(Blue_Vel);
}
if ((Blue_dir >= 525) && (Blue_dir <= 1000)) {
digitalWrite(Blue_DIR_PIN, LOW);
digitalWrite(Blue_STEP_PIN , HIGH);
digitalWrite(Blue_STEP_PIN , LOW);
//Serial.println(Blue_dir);
}
}
if ((unsigned long)(currentMillis - previousmillis_Yellow) >= Yellow_Vel) {
Yellow_dir = (analogRead(Yellow_Pot));
if (Yellow_dir <= 500) {
//Yellow_Vel = (10 + (Yellow_dir * 30));
Yellow_Vel = 10000;
}
if (Yellow_dir > 500) {
Yellow_Vel = (((analogRead(Yellow_Pot)) * 10) - 5000);
}
previousmillis_Yellow = currentMillis;
if (Yellow_dir <= 475) {
digitalWrite(Yellow_DIR_PIN, HIGH);
digitalWrite(Yellow_STEP_PIN , HIGH);
digitalWrite(Yellow_STEP_PIN , LOW);
//Serial.println(Yellow_dir);
//Serial.println(Yellow_Vel);
}
if ((Yellow_dir >= 525) && (Yellow_dir <= 1000)) {
digitalWrite(Yellow_DIR_PIN, LOW);
digitalWrite(Yellow_STEP_PIN , HIGH);
digitalWrite(Yellow_STEP_PIN , LOW);
//Serial.println(Yellow_dir);
}
}
if ((unsigned long)(currentMillis - previousmillis_White) >= White_Vel) {
White_dir = (analogRead(White_Pot));
if (White_dir <= 500) {
//White_Vel = (10 + (White_dir * 30));
White_Vel = 10000;
}
if (White_dir > 500) {
White_Vel = (((analogRead(White_Pot)) * 10) - 5000);
}
previousmillis_White = currentMillis;
if (White_dir <= 475) {
digitalWrite(White_DIR_PIN, HIGH);
digitalWrite(White_STEP_PIN , HIGH);
digitalWrite(White_STEP_PIN , LOW);
//Serial.println(White_dir);
//Serial.println(White_Vel);
}
if ((White_dir >= 525) && (White_dir <= 1000)) {
digitalWrite(White_DIR_PIN, LOW);
digitalWrite(White_STEP_PIN , HIGH);
digitalWrite(White_STEP_PIN , LOW);
//Serial.println(White_Pot);
}
}
if ((unsigned long)(currentMillis - previousmillis_Black) >= Black_Vel) {
Black_dir = (analogRead(Black_Pot));
if (Black_dir <= 500) {
//Black_Vel = (10 + (Black_dir * 30));
Black_Vel=10000;
}
if (Black_dir > 500) {
Black_Vel = (((analogRead(Black_Pot)) * 10) - 5000);
}
previousmillis_Black = currentMillis;
if (Black_dir <= 475) {
digitalWrite(Black_DIR_PIN, HIGH);
digitalWrite(Black_STEP_PIN , HIGH);
digitalWrite(Black_STEP_PIN , LOW);
//Serial.println(Black_dir);
//Serial.println(Black_Vel);
}
if ((Black_dir >= 525) && (Black_dir <= 1000)) {
digitalWrite(Black_DIR_PIN, LOW);
digitalWrite(Black_STEP_PIN , HIGH);
digitalWrite(Black_STEP_PIN , LOW);
//Serial.println(Black_dir);
}
}
if ((unsigned long)(currentMillis - previousmillis_Red) >= Red_Vel) {
Red_dir = (analogRead(Red_Pot));
if (Red_dir <= 500) {
//Red_Vel = (10 + (Red_dir * 30));
Red_Vel = 10000;
}
if (Red_dir > 500) {
Red_Vel = (((analogRead(Red_Pot)) * 10) - 5000);
}
previousmillis_Red = currentMillis;
if (Red_dir <= 475) {
digitalWrite(Red_DIR_PIN, HIGH);
digitalWrite(Red_STEP_PIN , HIGH);
digitalWrite(Red_STEP_PIN , LOW);
//Serial.println(Red_dir);
//Serial.println(Red_Vel);
}
if ((Red_dir >= 525) && (Red_dir <= 1000)) {
digitalWrite(Red_DIR_PIN, LOW);
digitalWrite(Red_STEP_PIN , HIGH);
digitalWrite(Red_STEP_PIN , LOW);
//Serial.println(Red_dir);
}
}
int value_temp = (analogRead(TEMP_0_PIN));
float TEMPERATURA = temp[value_temp];
if ((unsigned long)(currentMillis - previousmillis_temp) >= print_temp) {
previousmillis_temp = currentMillis;
Serial.print("Temperature ");
Serial.print(temp[value_temp]);
Serial.println(" Graus Celsius");
}