Skip to main content
Expanded on my answer after reading OP's comments.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

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.

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);

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.

Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

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);