Arduino Code to Read Voltages / Send to MATLAB via USB

Hi,

I have encountered this error: where it states "redefinition of Void Setup(), exit status 1. Could anyone help me on this?

/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
//float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(sensorValue);
}

#include <TimerOne.h>
byte end_count; // Declare variables for acquisition and sending commands
char inChar;
char serial_buffer[12] = " ";
float acquiredData[100]; // Initialize an array to store the readings from the analog input
const int timer_count = 10000; // Set the timer for the interrupt
const int numReadings = 100; // Set the number of readings to be taken from the analog input
int inputPin = A0; // Select analog pin to use

// ---------------------------------------
void setup()
{
pinMode(inputPin, INPUT); // Initialize the analog pin as an input
Serial.begin(57600); // Initialize serial communication with the computer
}
// ----------------------------------------
void loop()
{
if (Serial.available() > 0) // If the serial port receieves an input…
{
doSomething(); //…run doSomething function
}
}
// ----------------------------------------
void doSomething()
{
end_count = Serial.readBytesUntil(’!’, serial_buffer, 12); // Wait for character input
inChar = serial_buffer[end_count-1]; // The character we want is the last one before the ‘!’
switch(inChar)
{
case (‘a’):
acquire_data();
break;
case (‘r’):
transfer_data();
break;
}
}
// ------------------------------------------
void acquire_data()
{
Timer1.attachInterrupt(getData_ISR);
Timer1.initialize(timer_count);
delay(1100); // Wait for data acquisition (i.e. more than 1 second)
}
// -----------------------------------------
void getData_ISR()
{
static int numberAcquired = 0;
acquiredData[numberAcquired] = analogRead(inputPin); // Read the signal
numberAcquired++; // Move to next data point
if (numberAcquired > numReadings)
{
Timer1.stop(); // Stop the timer
numberAcquired = 0; // Reset the data point index to zero
}
}
// ------------------------------------------
void transfer_data()
{
int i; // Generic index variable
for (i=0; i<numReadings; i++) // Send analog values
{
end_count = Serial.readBytesUntil(’!’, serial_buffer, 12); // Wait for character input
Serial.println(acquiredData*); // Send data*

  • }*
    }
    // ------------------------------------------

You can't have two functions both named setup. You can't just copy and paste two pieces of code one after another and expect it to work. You're going to have to look at how both pieces work and put them together into one program.