Advertisement
hwthinker

control BTS7960 with arduino Uno by HwThinker

May 8th, 2018
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //BLDC sensorless 360W tester by HwThinker
  2. const int analogInPin = A0;  
  3. const int analogOutPin = 9;
  4. const int dirInPin = 13;
  5. const int dirOutPin = 12;
  6.  
  7. int sensorValue = 0;        // value read from the pot
  8. int outputValue = 0;        // value output to the PWM (analog out)
  9.  
  10. void setup() {
  11.   // initialize serial communications at 9600 bps:
  12.   Serial.begin(9600);
  13.   pinMode(dirInPin,INPUT_PULLUP);
  14.   pinMode(dirOutPin,OUTPUT);
  15. }
  16.  
  17. void loop() {
  18.   if(digitalRead(dirInPin)==LOW){
  19.     digitalWrite(dirOutPin,HIGH);
  20.   } else {
  21.     digitalWrite(dirOutPin,LOW);
  22.   }
  23.   // read the analog in value:
  24.   sensorValue = analogRead(analogInPin);
  25.   // map it to the range of the analog out:
  26.   outputValue = map(sensorValue, 0, 1023, 0, 255);
  27.   // change the analog out value:
  28.   analogWrite(analogOutPin, outputValue);
  29.  
  30.   // print the results to the Serial Monitor:
  31.   Serial.print("sensor = ");
  32.   Serial.print(sensorValue);
  33.   Serial.print("\t output = ");
  34.   Serial.println(outputValue);
  35.   delay(1);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement