I have been fighting with the Arduino for the last few years. this time I wanted to simplify my code base by using a struct in my header file:
// typdef struct frequency { int bits[20][5] = {{1,1,0,0,1},{1,1,0,0,0},{1,1,1,0,0},{1,0,0,0,1},{1,1,1,1,0}, {0,0,0,1,0},{0,1,1,1,1},{0,0,1,0,0},{1,0,1,1,1},{0,1,0,0,0}, {0,0,0,1,1},{1,0,0,0,0},{1,0,1,0,1},{0,0,0,0,1},{0,0,1,1,0}, {0,1,0,1,1},{0,0,1,0,1},{0,0,1,1,0},{1,0,0,1,0},{0,1,1,0,0}};
char channels[20][3]= {{000},{108},{109},{110},{111},{112},{113},{114},{115},{116},{117}, {118},{119},{120},{121},{122},{123},{124},{125},{126}};
// } channels; |
#include "C3436.h" int Status; int F[5]={};
void setup() { // put your setup code here, to run once: // Start serial port Serial.begin( 9600 );
// Khz Pins for (int i = 1; i < 6; i++){ pinMode (pins[i], INPUT_PULLUP);} // Mhz Pins for (int ii = 6; ii < 11; ii++){ pinMode (pins[ii], INPUT_PULLUP);} // Other stuff pinMode ( powerpin, INPUT_PULLUP ); pinMode ( lightPower, OUTPUT); } |
This has been a disaster, in a function I tried in vain to access the channels.bits[][] member but to no avail. In my function I can access bits[][] but not as a member of the struct.
My code is posted below: I have been having cold stupid sweats about stupid scoping rules which don't make any sense to me as a C programmer. Even the silliness of the loop() is a little nutty. Once in it how the hell do you get out of it. Also when you call an ISR it is a void so you have to use a side effect (a bad thing), ISRs normally return something. I am going to use bare metal C programming. Here is a nice article on how to do it, he likes the silly platformIO, which is based on Mico$oft's Visual Studio, which is something that I want no part of. Me, I'm going to stick with my Swiss Knife, Eclipse IDE, it is clean and uncluttered. I will be using GCC for the AVR.
void loop() |
---|
void loop() {
int Stat = start(); if( Stat == 1 ) run(); } |
int start() |
int start( ) { // check pwrpin int pwrpin= digitalRead(powerpin); pwrpin = 1; // force power on switch ( pwrpin ) { case 0: { pwrpin = 0; break;} case 1: { pwrpin = 1; break;} default: { pwrpin = -1; break;} } return pwrpin; } |
void run () |
void run () {
int x; int temp[10];
// read the freq pins for ( x = 0; x < 10; x ++) { temp[x] = digitalRead( pins[x]); }
// Now test the KHz pins; test columns using double loops for (int y = 0; y < 10; y++){ for (int x = 0; x < 5; x++ ){ if ( temp[x] == lowFrequency[x][y] ) { continue; } else { break; } }}
// Now test the Mhz pins for (int y = 0; y < 20; y++){ for (int x = 0; x < 5; x++ ){ // if ( temp[x] == channels.bits[x][y] ) { if ( temp[x] == bits[x][y] ) { continue; } else { break; } }}
} |