Escolar Documentos
Profissional Documentos
Cultura Documentos
3 RETORNOS
SINTAXE:
//Executa algo
103
Segundo: para retornar o valor desejado, usa-se a sintaxe
return.
Serial.println(func_com_retorno());
int x = func_com_retorno();
EXEMPLO
//experimente mudar esses valores para testar os resultados
int x = 50;
int y = 12;
void setup() {
Serial.begin(9600); // inicia a Serial
int somatorio = soma(); // atribui o retorno da função na
variável somatorio
Serial.println(somatorio); //imprime o valor que foi
atribuido a variável somatorio
}
void loop() {
}
int soma() {
104
return x + y; //retorna a soma de x + y
}
105
PROJETO#9 – Lendo um sensor de
temperatura:
Componentes:
• 1 - Arduino Uno
• 1 - Protoboard
• 1 – Sensor de Temperatura – TMP36
• Jumpers
Diagrama:
106
/*
void setup()
{
Serial.begin(9600); // inicializa a Serial
}
void loop()
{
float voltage, degreesC, degreesF; //declara 3 variáveis
float, para o armazenamento da tensão, graus célsius e
graus Fahrenheit
Serial.print("voltagem: ");
Serial.print(voltage);
Serial.print(" Graus C: ");
Serial.print(degreesC);
Serial.print(" Graus F: ");
Serial.println(degreesF);
107
}
// Criar um termostato
108