I realise that this isnt complete yet, however I am having real trouble with this programming, I have used the examples pages but I am struggling to figure out my errors. Any help would be greatly appreciated.

The idea behind this is to read each of the 8 analog inputs, only one of them will have an input at a time, as theyre connected to plates on a slider. Once it determines which is high, it then runs the subroutine to calculate (10 bit) the voltage level.

Well, thats what its supposed to do

int A0pin = 19;
int A1pin = 20;
int A2pin = 21;
int A3pin = 22;
int A4pin = 23;
int A5pin = 24;
int A6pin = 25;
int A7pin = 26;
int analogValue;
void setup()
{
}
void loop()
int (analogValue = analogRead(A0pin));
if (analogValue < 100) {
Calc();
}
int (analogValue = analogRead(A1pin));
if (analogValue < 100) {
Calc();
}
int (analogValue = analogRead(A2pin));
if (analogValue < 100) {
Calc();
}
int (analogValue = analogRead(A3pin));
if (analogValue < 100) {
Calc();
}
int (analogValue = analogRead(A4pin));
if (analogValue < 100) {
Calc();
}
int (analogValue = analogRead(A5pin));
if (analogValue < 100) {
Calc();
}
int (analogValue = analogRead(A6pin));
if (analogValue < 100) {
Calc();
}
int (analogValue = analogRead(A7pin));
if (analogValue < 100) {
Calc();
}
void Calc()
{
}

sketch_feb25a:18: error: expected initializer before ‘int’
sketch_feb25a:19: error: expected unqualified-id before ‘if’
sketch_feb25a:22: error: expected )' before '=' token sketch_feb25a:23: error: expected unqualified-id before 'if' sketch_feb25a:26: error: expected )’ before ‘=’ token
sketch_feb25a:27: error: expected unqualified-id before ‘if’
sketch_feb25a:31: error: expected )' before '=' token sketch_feb25a:32: error: expected unqualified-id before 'if' sketch_feb25a:36: error: expected )’ before ‘=’ token
sketch_feb25a:37: error: expected unqualified-id before ‘if’
sketch_feb25a:41: error: expected )' before '=' token sketch_feb25a:42: error: expected unqualified-id before 'if' sketch_feb25a:46: error: expected )’ before ‘=’ token
sketch_feb25a:47: error: expected unqualified-id before ‘if’
sketch_feb25a:51: error: expected `)’ before ‘=’ token
sketch_feb25a:52: error: expected unqualified-id before ‘if’

h4nsn:
You have no opening and closing bracers in your loop() function.

Damn, I cant believe I overlooked that, I spent ages trying to figure that out. Putting that in corrected all the other errors too!

AWOL:

int (analogValue = analogRead(A0pin));

if (analogValue < 100) {
Calc();
}

What's that?

That is supposed to check analogue vlavue at A0, and store it in ‘analogValue’ - If the value is more than 100 then its the active analog input and it should run the subroutine Calc().
If the value is less than 100, it moves to the next analog input, and checks that etc.

Note - I have my < and > mixed up, corrected them now.

I havent written the calc yet, Im just working as I go, writing it in stages so I dont get the end and its all wrong.

By the way your code could be reduced to just a couple of lines.
Whenever you find yourself repeating a lot of code a function or loop is probably a better alternative.

loop()
{
int i;
for (i = 19; i < 27; ++i) {
if (analogRead(i) > 100)
calc(i);
}
}

Thats a much simpler way of doing this! So with Arduinos, it just knows that 19 incremented to 27 means the pin numbers, and not just an integer number?

I'm pretty new to the arduino thing myself, but arent analog inputs written like 'A0, A1, A2..' etc? I.E not just normal integers '1, 2, 3...'

this is what was confusing me, in some of the examples, they have things like that "int Sensor = 19 // sensor is pin 19". I took this to mean that they were using this to set pin numbers to a word.

Really appreciate your feedback my friend. Im going to get started now on figuring out how to get my subroutine to determine which 1/8 of the voltage scale its in! 0-1023 is the standard 10 bit resolution.

Ok ive made some progress throughout today. I am at the stage now where I am stuck again.

I am under the impression that so far, this code checks 8 analog inputs in turn, searching for the one with an input, it takes the value of the analog voltage and uses it in the “voltage” function, to determine which 1/8 of the voltage band it is in.
once determined, its moves to the conversion function, which turn both the 1-8 analog options, and the 1-8 voltage levels, and converts them into a single binary ranging from 00000000 upto 01110111. Basically giving a reading of 1-64 in binary.

I now need to convert this back to decimal so that I can continue to use it in further calculations. Any help here, and feedback on the whole coding would be very much appreciated.

As can be seen in the attachment, its basically just trying to find the location of the slider to a 1/64 resolution. 8 large plates with 8 possible voltages.

int i; // large plate
int x;
int a; // small platelet
int b; // large plate
void setup()
{
}
void loop()
{
for (i = 19; i < 27; ++i) {
if (analogRead(i) > 100)
voltage(i);
}
}
int voltage(int x)
{
float voltage = x * (5.0 /1023.0);
if (voltage > 4.3515)
convert(8);
if (voltage < 4.3515) && (voltage > 3.7305)
convert(7);
if (voltage < 3.7305) && (voltage > 3.1105)
convert(6);
if (voltage < 3.1105) && (voltage > 2.4915)
convert(5);
if (voltage < 2.4915) && (voltage > 1.874)
convert(4);
if (voltage < 1.874) && (voltage > 1.2595)
convert(3);
if (voltage < 1.2595) && (voltage > 0.6535)
convert(2);
if (voltage < 0.6535)
covert(1);
}
int convert(int w)
{
int myNum = w;
int zeros = 8 - String(myNum,BIN).length();
String platelet;
for (int i=0; i<zeros; i++) {
platelet = platelet + "0";
}
platelet = platelet + String(myNum,BIN);
int MyNum = i;
int zeros = 8 - String(MyNum,BIN).length();
String plate;
for (int i=0; i<zeros; i++) {
plate = plate + "0";
}
plate = plate + String(MyNum,BIN);
platelet = a;
plate = b;
calc(a, b)
}
int calc(int y, int z)
{
uint8_t lower_part = y;
uint8_t upper_part = z;
uint8_t result = 0; // accumulator to build result
result |= (lower_part & 0b00001111); // i
result |= ((upper_part & 0x00001111) << 4); //
}
// "print" result = 0b 0011 0101

krugerr:
Any help here, and feedback on the whole coding would be very much appreciated.

I'm a bit slow today so I'm not going to be much help on solving your problem, but from looking at your code a few general thoughts come to mind:

Variable Names: Never use one character names for globals - it's always better to use something descriptive so it helps the reader - and you later - understand the code.

Strings: Just say no. Use an array of characters and functions such as itoa and strlen (convert ints to strings, returns the length of a string

If you don't know how arrays work, you should learn how and reduce the size of your code

I think having functions (which you ignore the return values of) for voltage, convert, and calc is a bit much - you should only need one routine plus loop and then only to keep the size of your main loop smaller

Again I'm slow but I don't see the point of calling convert and losing the voltage value

Hey - i am currently reading up on Arrays, although Im not sure how to implement this into my code, yet
currently the functions calculate different aspects of the problem, then, when I get around to it, hopefully use all those solutions to calculate the exact location of the pin on the slider.

Can I ask why we should avoid string use? I am investigating array use however

int convert(int w)
{
int myNum = w;
int zeros = 8 - String(myNum,BIN).length();
String platelet;
for (int i=0; i<zeros; i++) {
platelet = platelet + "0";
}
platelet = platelet + String(myNum,BIN);
int MyNum = i;
int zero = 8 - String(MyNum,BIN).length();
String plate;
for (int i=0; i<zero; i++) {
plate = plate + "0";
}
plate = plate + String(MyNum,BIN);
int Plate = plate.toInt();
int Platelet = platelet.toInt();
calc(Platelet, Plate);
}
int calc(int y, int z)
{
uint8_t lower_part = y;
uint8_t upper_part = z;
uint8_t result = 0; // accumulator to build result
result |= (lower_part & 0b00001111); // i
result |= ((upper_part & 0x00001111) << 4); //
}
}

Int w and int i - these are values of 1-8 and are from further up in the, this function is supposed to turn them both into binary, and shift one of them up so that a reading 64 different combinations are availble.

krugerr:
Can I ask why we should avoid string use? I am investigating array use however

There is a big difference between a string (c-style character array) and a String data type. Spend a few days reading the forums and it comes up every couple of days (or check out http://forum.arduino.cc/index.php/topic,112067.0.html for an decent discussion).