user46897: I am getting an error that I have never seen before and don't know how to fix. Basically I am trying to print a string (stored in thermistor) to the serial monitor. When I run the code I get an error message that says: exit status 1
'Serial' does not name a type. 
What can I do fix this error?
void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(8, OUTPUT);

}

void loop() {

} <==== ERROR: loop() ENDS TOO EARLY
String heartMonitor = codeWrite(4, HIGH, LOW, HIGH);
String lilyPad = codeWrite(6, HIGH, LOW, LOW);
String thermistor = codeWrite(8, HIGH, HIGH, LOW);
Serial.println(thermistor);
delay(1000);


String codeWrite(int pin, char output1, char output2, char output3)
{
  digitalWrite(pin, output1);
  int A = digitalRead(pin);
  delay(1);
  digitalWrite(pin, output2);
  int B = digitalRead(pin);
  delay(1);
  digitalWrite(pin, output3); 
  int C = digitalRead(pin);
  delay(11);
  String code = String(A) + String(B) + String(C);
  <==== ERROR: MISSING RETURN STATEMENT
}


user37523: If you move this code into loop(), the sketch will compile.
String heartMonitor = codeWrite(4, HIGH, LOW, HIGH);
String lilyPad = codeWrite(6, HIGH, LOW, LOW);
String thermistor = codeWrite(8, HIGH, HIGH, LOW);
Serial.println(thermistor);
delay(1000);

EDIT:
The sketch should look like this:
void setup() {
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop() {
  String heartMonitor = codeWrite(4, HIGH, LOW, HIGH);
  String lilyPad = codeWrite(6, HIGH, LOW, LOW);
  String thermistor = codeWrite(8, HIGH, HIGH, LOW);
  Serial.println(thermistor);
  delay(1000);
}

String codeWrite(int pin, char output1, char output2, char output3)
{
  digitalWrite(pin, output1);
  int A = digitalRead(pin);
  delay(1);
  digitalWrite(pin, output2);
  int B = digitalRead(pin);
  delay(1);
  digitalWrite(pin, output3); 
  int C = digitalRead(pin);
  delay(11);
  String code = String(A) + String(B) + String(C);
}

The issue is the code can not be outside of a function.

46897: <p>I am getting an error that I have never seen before and don't know how to fix. Basically I am trying to print a string (stored in <code>thermistor</code>) to the serial monitor. When I run the code I get an error message that says: exit status 1
'Serial' does not name a type. </p>

<p>What can I do fix this error?</p>

<pre><code>void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(8, OUTPUT);

}

void loop() {

} &lt;==== ERROR: loop() ENDS TOO EARLY
String heartMonitor = codeWrite(4, HIGH, LOW, HIGH);
String lilyPad = codeWrite(6, HIGH, LOW, LOW);
String thermistor = codeWrite(8, HIGH, HIGH, LOW);
Serial.println(thermistor);
delay(1000);


String codeWrite(int pin, char output1, char output2, char output3)
{
  digitalWrite(pin, output1);
  int A = digitalRead(pin);
  delay(1);
  digitalWrite(pin, output2);
  int B = digitalRead(pin);
  delay(1);
  digitalWrite(pin, output3); 
  int C = digitalRead(pin);
  delay(11);
  String code = String(A) + String(B) + String(C);
  &lt;==== ERROR: MISSING RETURN STATEMENT
}
</code></pre>
 37523: <p>If you move this code into loop(), the sketch will compile.</p>

<pre><code>String heartMonitor = codeWrite(4, HIGH, LOW, HIGH);
String lilyPad = codeWrite(6, HIGH, LOW, LOW);
String thermistor = codeWrite(8, HIGH, HIGH, LOW);
Serial.println(thermistor);
delay(1000);
</code></pre>

<p>EDIT:</p>

<p>The sketch should look like this:</p>

<pre><code>void setup() {
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop() {
  String heartMonitor = codeWrite(4, HIGH, LOW, HIGH);
  String lilyPad = codeWrite(6, HIGH, LOW, LOW);
  String thermistor = codeWrite(8, HIGH, HIGH, LOW);
  Serial.println(thermistor);
  delay(1000);
}

String codeWrite(int pin, char output1, char output2, char output3)
{
  digitalWrite(pin, output1);
  int A = digitalRead(pin);
  delay(1);
  digitalWrite(pin, output2);
  int B = digitalRead(pin);
  delay(1);
  digitalWrite(pin, output3); 
  int C = digitalRead(pin);
  delay(11);
  String code = String(A) + String(B) + String(C);
}
</code></pre>

<p>The issue is the code can not be outside of a function.</p>
