Can 5v pro mini handle being hooked up to 12v on the raw pin? I keep wrecking minis maybe its back emf?
The sne. I have two ics bridged and stacked. which should output enough amps. I have a 7812 connected to my 3d printer power supply but its going to have Alkaline batteries in the end.
All grounds are tied together with solder
I have 5v pin to vcc on mini
Enable pins are tied together
Motor out
Left and right to respective arduino pins
In the code below I know feather outputs 3.3 and pro mini wants 5 for HIGH but i read somewhere not 0 is equal to 1 in coding? Is that true for this code as well?
Can you suggest a cleaner way of writing my if statements I think theres a way of simplifying it.
Should I just tie all of the Enable pins all HIGH?
// This code is intended to go into a pro mini
const int enablePin = 2; //to sne75441 enable
const int motorPin1 = 4; // to sne 75441 left motor
const int motorPin2 = 6; // to sne 75441 right motor
int analogPin1 = A0;// pin from feather to pro mini
int analogPin2 = A1; //up
int analogPin3 = A2; //down
int ledState = LOW; // int to store state of radio pin read.
/*would love to create a delay function in between state changes to reduce back emf but i dont know how.*/
unsigned long previousMillis = 0;
unsigned long interval = 3000;
void setup() {
pinMode( enablePin, OUTPUT); // to both enable pins on 7544
pinMode( motorPin1, OUTPUT); // to left motor pin on 7544
pinMode( motorPin2, OUTPUT);// to right motor pin on 7544
pinMode( analogPin1, INPUT); // from feather to pro mini A0
pinMode( analogPin2, INPUT);// from 5v to nc switch to A01 (pulldown resistor)
pinMode( analogPin3, INPUT);// from 5v to nc switch to A02 (pulldown resistor)
Serial.begin(9600);
}
void loop() {
ledState = digitalRead(analogPin1); // read feather pin 3.3
int buttonVal1 = (ledState);
int buttonVal2 = digitalRead(analogPin2);
int buttonVal3 = digitalRead(analogPin3);
if (buttonVal1 == 1 && buttonVal3 == 1) { //all the way in. Go out
forwards();
}
if (buttonVal1 == 1 && buttonVal2 == 0) { // moving out not at the end. Go out
forwards();
}
if (buttonVal1 == 1 && buttonVal3 == 0) { // moving out not at the end. Go out
forwards();
}
if (buttonVal1 == 1 && buttonVal2 == 1) { // All the way out. Stop
Stop();
}
if (buttonVal1 == 0 && buttonVal2 == 1) { // no signal endstop hit. Go in
Backwards();
}
if (buttonVal1 == 0 && buttonVal2 == 0) {// no signal no endstop hit. Go in
Backwards();
}
if (buttonVal1 == 0 && buttonVal3 == 1) {// all the way in. Stop
Stop();
}
if (buttonVal1 == 1 && buttonVal3 == 1) {// Shtf. Stop
Stop();
}
//////////
// print the analog value:
Serial.print(buttonVal1);
Serial.print(buttonVal2);
Serial.println(buttonVal3);
delay(1); // delay in between reads for stability
}
//////////////////////////////////////
void forwards()
{
digitalWrite(enablePin, HIGH);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
}
void Backwards()
{
digitalWrite(enablePin, HIGH);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
}
void Stop()
{
digitalWrite(enablePin, LOW);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
}
void delaytime()
{
//bring the pins low for one half second between changes to keep back emf down
}