Questions about multiple *.cpp files and how to define the pin definitions so that it compiles.
The pin label definitions are in the main "INO" file before setup()
int PULSE=9; //PulseGen -Routines
int Xp = 2; //Indexer
int Yp = 3; //Indexer
int Ep = 4; //Indexer
int LDn = 9; //Prescaler ena
int FREQ= 8; //Prescaler in
int DD_SCLK=13; //SPI Clk
int DD_MOSI=11;
int D_C = 7; //OLED & SineGen
int CS1 =10; //OLED ??also called slave select??
int CS2 = 5; //SineGen
int AD =A0; //Volt input
void Setup ()
{
SPI.setClockDivider(SPI_CLK_DIV4);
Serial.begin(9600); //initialize Serial UART
InitTimersSafe();
bool success =SetPinFrequencySafe(9, frequency);
if (success)
{
pinMode(13, OUTPUT);
digitalWrite(13,HIGH);
}
pinMode(CS1, OUTPUT); //OLED SS or Chip Select not.
pinMode(D_C, OUTPUT); //OLED Data or Command
pinMode(DD_SCLK, OUTPUT);
pinMode(DD_MOSI, OUTPUT);
pinMode(PULSE, OUTPUT);
pinMode(CS2, OUTPUT);
pinMode(Xp, INPUT);
pinMode(Yp, INPUT);
pinMode(Ep, INPUT);
pinMode(LDn, OUTPUT);
pinMode(FREQ, INPUT);
pinMode(AD, INPUT);
digitalWrite(CS1, HIGH);
digitalWrite(CS2, HIGH);
digitalWrite(LDn, LOW);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
}
== ONE OF THE CPP files that uses these pin parameters
=======OLED_display.cpp==========
// OLED_display.cpp
// Author : Fred Hamori
//-------------------------------------------------
#include <Arduino.h>
#include "Functions.h"
#include <SPI.h>
int CS1 =10; //OLED
int D_C = 7; //OLED & SineGen
int DD_MOSI =11;
int DD_SCLK = 13;
//int DD_SPI=13;
each one of these "redefines" is marked as an error
"previously defined here"
but if they are removed then they also create an error.
"was not declared in this scope"
One example of a function that uses these variables/pins
void OLED_cmd_wr(unsigned char command)
{
digitalWrite(D_C, LOW); // Command mode
digitalWrite(CS1, LOW); // SPI CS on
SPDR = command; // write cmd to LCD
while (!(SPSR & (1<<SPIF))); // wait til end of xfer
digitalWrite(CS1, HIGH); //terminate xfer
}
The C compilers I've used before declared pins differently and the Arduino IDE
is confusing to me since the pins were not redefined in those .cpp pages again, but were only listed once in the *.h files. That is different here since they are listed in the start of the INO file and somehow are supposed to be listed in the using .cpp file. But how?
When it comes to the high level segmentation of the Arduino program, there is little information that is clear (to me).