Accessing Values From Array Within a Library

There are many great examples of how to access information from an array on the net. I ran into a specific case that has me confused. I am using a library for attiny 85 TinyPpmReader.h. This is a simple library that will take PPM signals in from a RC receiver running in pulse position mode and allows you to attach to a pin to process input. Easy enough.

In the code below, I ran into some confusion when trying to access the data in the array. I am trying to filter out a single channel in the ppm stream and print the contents of only 1 channel (Original example prints 8 channels) and eventually map that value to a servo. (I pasted the serial monitor ouput at the end of the code)

I tried accessing the variable stored in the array like this:


void loop()
{
for(uint8_t Idx = 1; Idx <= TinyPpmReader.detectedChannelNb(); Idx++) /* From Channel 1 to Max detected */

if(TinyPpmReader.detectedChannelNb == [5]) //Is this channel 6 in index 0-7?
{
Serial.println(TinyPpmReader.width_us[5); // if so, print only index 5 containing channel 6 values
}
delay(500);
}

Example unedited sketch from library

#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("* Period="));Serial.print((int)TinyPpmReader.ppmPeriod_us());Serial.println(F(" us "));
Serial.print(F("ChNb="));Serial.println((int)TinyPpmReader.detectedChannelNb());
for(uint8_t Idx = 1; Idx <= TinyPpmReader.detectedChannelNb(); Idx++) /
From Channel 1 to Max detected */
{
Serial.print(F("Ch"));Serial.print(Idx);Serial.print(F("="));Serial.print(TinyPpmReader.width_us(Idx));Serial.println(F(" us"));
}

delay(500);
}


This example script prints to the serial console (Uno to attiny85)

Note: There is some formating errors in the output. The original example does not
print the ASCII channel numbers only the char column of the ASCII table.
I have inserted the channel numbers after "ch" below for clarity.


  • Period=17928 us *
    ChNb=8
    Ch=1496 us
    Ch=1744 us
    Ch=896 us
    Ch=1560 us
    Ch=1640 us
    Ch=1496 us
    Cha=1536 us
    Ch=1688 us

Any suggestions? It is probably something simple but I dont think I am googling the correct question to get the correct answer.

Also posted at:

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

I tried accessing the variable stored in the array like this:

Why is the 5 in square brackets? Why are you trying to compare [5] to the address of the detectedChannelNb function in the TinyPpmReader class?

if(TinyPpmReader.detectedChannelNb() == 5) //Is this channel 6 in index 0-7?