These are the values that made the needle move though it's range
9v, 1500 ohm = 2000 rpm
9v, 1000 ohm = 3100 rpm
9v, 667 ohm = 4225 rpm
9v, 390 ohm = 6650 rpm
9v, 330 ohm = 7600 rpm
The compiling works up until the interpolators, just after the unsigned long rpm_look_up = micros() - start; . I copy pasted the interpolators, so I don't know how they really work.
#define frequency_output MISO
#define volt_sense PCINT3
#define coil_neg SCK
void setup() {
// put your setup code here, to run once:
pinMode(frequency_output, OUTPUT);
pinMode(volt_sense, INPUT);
pinMode(coil_neg, INPUT);
int default_frequency(0);
int volt_mod(0);
unsigned long pulse_time(0);
digitalWrite(frequency_output, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
// Voltage measuring
while ((SCK) == 0)
; //wait for High on Pin2 of PORTB
unsigned long start = micros();
while (SCK)
; //wait for Low
while ((SCK) == 0)
; //wait for High
unsigned long rpm_look_up = micros() - start;
// Start of rpm interpolation
//Look up table for RPM to frequency output.
rpm_look_up; c[5] = {
{ 300, 10.02 },
{ 700, 89.542 },
{ 800, 126.452 },
{ 900, 171.453 },
{ 1500, 225.123 }
};
double default_frequency(rpm_look_up * c, double x, int n) //Default_frequency is output #
{
int i;
for (i = 0; i < n - 1; i++) {
if (c[i].x <= x && c[i + 1].x >= x) {
double diffx = x - c[i].x;
double diffn = c[i + 1].x - c[i].x;
return c[i].y + (c[i + 1].y - c[i].y) * diffx / diffn;
}
}
return 0; // Not in Range
}
int main(int argc, char** argv) {
double y = Default_frequency(c, 850, 5);
}
//Volt sensing
int analogIn = analogRead(volt_sense); // Read analog voltage on pin PCINT3
// voltage interpolation
typedef volt_sense {
double x;
double y;
}
volt_to_mod; //Look up table for RPM to frequency output.
volt_to_mod c[2] = {
{ 0, 0 },
{ 5, 1 }
};
double volt_mod(volt_to_mod * c, double x, int n) //volt_mod is output variable
{
int i;
for (i = 0; i < n - 1; i++) {
if (c[i].x <= x && c[i + 1].x >= x) {
double diffx = x - c[i].x;
double diffn = c[i + 1].x - c[i].x;
return c[i].y + (c[i + 1].y - c[i].y) * diffx / diffn;
}
}
return 0; // Not in Range
}
int main(int argc, char** argv) {
double y = volt_mod(c, 850, 5);
}
//Multiplication
int frequency_output = volt_mod * default_frequency;
//Output
analogWrite(frequency_output); // Output PWM
}
These are all of the errors.
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino: In function 'void loop()':
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:29:16: error: 'c' was not declared in this scope
rpm_look_up; c[5] = {
^
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:36:45: error: expected primary-expression before 'double'
double default_frequency(rpm_look_up * c, double x, int n) //Default_frequency is output #
^~~~~~
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:36:55: error: expected primary-expression before 'int'
double default_frequency(rpm_look_up * c, double x, int n) //Default_frequency is output #
^~~
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:48:35: error: a function-definition is not allowed here before '{' token
int main(int argc, char** argv) {
^
In file included from c:\users\user\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\io.h:272:0,
from c:\users\user\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\pgmspace.h:90,
from C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.7\cores\arduino/Arduino.h:28,
from C:\Users\User\AppData\Local\arduino\sketches\CAE7CE3AF2F45DE198D58CFB12EC7FF4\sketch\Tachometer_project_V1.3.ino.cpp:1:
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:2:20: error: expected unqualified-id before numeric constant
#define volt_sense PCINT3
^
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:55:11: note: in expansion of macro 'volt_sense'
typedef volt_sense {
^~~~~~~~~~
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:59:3: error: 'volt_to_mod' was not declared in this scope
volt_to_mod; //Look up table for RPM to frequency output.
^~~~~~~~~~~
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:59:3: note: suggested alternative: 'port_to_mode_PGM'
volt_to_mod; //Look up table for RPM to frequency output.
^~~~~~~~~~~
port_to_mode_PGM
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:60:15: error: expected ';' before 'c'
volt_to_mod c[2] = {
^
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:64:36: error: expected primary-expression before 'double'
double volt_mod(volt_to_mod * c, double x, int n) //volt_mod is output variable
^~~~~~
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:64:46: error: expected primary-expression before 'int'
double volt_mod(volt_to_mod * c, double x, int n) //volt_mod is output variable
^~~
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:76:35: error: a function-definition is not allowed here before '{' token
int main(int argc, char** argv) {
^
C:\Users\User\Documents\Arduino\Tachometer_project_V1.3\Tachometer_project_V1.3.ino:82:31: error: too few arguments to function 'void analogWrite(uint8_t, int)'
analogWrite(frequency_output); // Output PWM
^
In file included from C:\Users\User\AppData\Local\arduino\sketches\CAE7CE3AF2F45DE198D58CFB12EC7FF4\sketch\Tachometer_project_V1.3.ino.cpp:1:0:
C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.7\cores\arduino/Arduino.h:139:6: note: declared here
void analogWrite(uint8_t pin, int val);
^~~~~~~~~~~
exit status 1
Compilation error: 'c' was not declared in this scope