Created
April 24, 2023 14:48
-
-
Save rahji/bf52eec4ab1b7023633384859aa8d1bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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