//**************************************************************** //* Name : RC Dyno * //* Author : Robert Joseph Korn * //* Notice : Copyright (c) 2015 Open Valley Consulting Corp * //* Date : 12/15/15 * //* Version : 1.75 * //* Notes : * //* : * //**************************************************************** float voltage ; float current ; long thrust ; #define PD_SCK 2 #define DOUT 3 void setup() { pinMode(PD_SCK, OUTPUT); pinMode(DOUT, INPUT); digitalWrite(PD_SCK, LOW); Serial.begin(115200); while(!Serial){ delay(100); } } void loop() { voltage = analogRead(A0); current = analogRead(A1); voltage = map(voltage, 0,343,0,500); current = constrain(current, 512, 1023); current = map(current, 512,570,0,280); thrust = readhx()/400-21091; // Serial.print(millis()); // Serial.print(","); Serial.print(thrust); Serial.print(","); Serial.print(voltage/100); Serial.print(","); Serial.print(current/100); Serial.println(","); delay(100); } bool is_ready() { return digitalRead(DOUT) == LOW; } long readhx() { // wait for the chip to become ready while (!is_ready()); delay(2); unsigned long Count; unsigned char i; Count = 0; // pulse the clock pin 24 times to read the data for (i=0; i<24; i++) { digitalWrite(PD_SCK, HIGH); if(digitalRead(DOUT) > 0){ Count++; } digitalWrite(PD_SCK, LOW); Count=Count<<1; delay(1); } digitalWrite(PD_SCK, HIGH); delay(1); digitalWrite(PD_SCK, LOW); Count=Count^0x800000; return Count; }