Skip to content

Instantly share code, notes, and snippets.

@rahji
Created April 24, 2023 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahji/bf52eec4ab1b7023633384859aa8d1bf to your computer and use it in GitHub Desktop.
Save rahji/bf52eec4ab1b7023633384859aa8d1bf to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#define EnablePin 3
#define PhasePin 4
#define CSPin A0
unsigned long lastTime = 0;
int highestCurrent = 0;
int direction = HIGH;
void setup() {
Serial.begin(9600);
pinMode(EnablePin, OUTPUT);
pinMode(PhasePin, OUTPUT);
pinMode(CSPin, INPUT);
}
void loop() {
if (millis() - lastTime >= 5000) {
digitalWrite(EnablePin, HIGH);
digitalWrite(PhasePin,direction);
direction = !direction;
lastTime = millis();
}
int currentSense = analogRead(CSPin);
if (currentSense > highestCurrent) {
Serial.print("Highest: " + currentSense); // 2500 mV/A
float inAmps = map(currentSense,0,1023,0,2);
Serial.print("aka, in Amps: ");
Serial.print(inAmps, 3);
highestCurrent = currentSense;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment