This question is an extension of this question.
Accessing Values From Array Within a Library
The answer provided by Mark showed me how to read and print a single value from a particular array by using the index number to print to the serial console.
The second part of this question is how to get these values from the array to map to 0-180 for values that are useful to the servo.
The below code is my attempt that is not working. I used the servo sweep example from the Arduino examples which worked fine with a potentiometer but not with the ppm input. What am I doing wrong here? This won't compile. (I am using TinyServo.h library since this is for an attiny85. Works with with the pot mapping just fine.)
#include <TinyServo.h>
#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>
int PPM_INPUT_PIN = TinyPpmReader.width_us(3); //<------- Doesn't work
//int potpin0 = 3; <--------- // This worked
int val0; // integer to store value
const byte SERVOS = 1; // how many servos do you have? up to 5 on ATTiny85 and 8 on ATtiny84/2313
const byte servoPin[SERVOS] = { 0 }; // what pins are your servos on?
// you have the option to give your servos nice names. 0 refers to the first servo pin above, 1 to the second, etc
#define PANSERVO 0
#define PPM_INPUT_PIN 2 <--------- //define pin for ppm input
void setup()
{
setupServos();
}
void loop()
{
val0 = analogRead(PPM_INPUT_PIN); <--------- //Doesnt work// reads the value of the potentiometer (value between 0 and 1023) // reads the value of the 2nd potentiometer (value between 0 and 1023)
val0= map(val0, 1000, 2000, 0, 180);
// scale it to use it with the servo (value between 0 and 180)
// scale it to use it with the servo (value between 0 and 180)
moveServo(PANSERVO, val0);
delay(5); // waits for the servo to get there
}
For some background, the ppm library outputs like this to the serial monitor:
Ch4=1560 us
These values move from ~1000 - 2000 depending on the ppm signal input. (The input is from a RC remote control receiver)
This example below prints only channel 4 (Ch4=1560 us)from a total of 8 channels. Now, I want to map this to the values of 0-180:
#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>
#define PPM_INPUT_PIN 2
void setup()
{
Serial.begin(38400);//attiny tx - rx uno does not work at 9600 baud. Set to 38400 @ attiny 1mhz and uno serial console to 38400 baud
TinyPpmReader.attach(PPM_INPUT_PIN); /* Attach TinyPpmReader to PPM_INPUT_PIN pin */
}
void loop()
{
Serial.print(F("Ch"));Serial.print(3);Serial.print(F("="));Serial.print(TinyPpmReader.width_us(3));Serial.println(F(" us"));
display results */
delay(500);
}
What am I doing wrong?
int PPM_INPUT_PIN = TinyPpmReader.width_us(3);
contain a reading result, when followed byval0 = analogRead(PPM_INPUT_PIN);
it's clearly absurd.