Velha Ball: 6) Construção do algoritmo do jogo – Programação;
Nesta seção estão listadas as referências, pesquisas e testes realizados durante o desenvolvimento do algoritmo/programa do jogo.
Deixe um comentário
Você precisa fazer o login para publicar um comentário.
6 Comentários
Código fonte do programa Blink
Lembrando que na programação do Arduino, o programa é chamado também de Sketch.
O programa Blink está na aba File/Examples e o que ele faz é: piscar o led associado a porta digital 13.
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Sketch: Knock
Programa exemplo do Arduino que detecta uma vibração na cápsula piezoelétrica.
/* Knock Sensor
This sketch reads a piezo element to detect a knocking sound.
It reads an analog pin and compares the result to a set threshold.
If the result is greater than the threshold, it writes
“knock” to the serial port, and toggles the LED on pin 13.
The circuit:
* + connection of the piezo attached to analog in 0
* – connection of the piezo attached to ground
* 1-megohm resistor attached from analog in 0 to ground
http://www.arduino.cc/en/Tutorial/Knock
created 25 Mar 2007
by David Cuartielles <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
*/
// these constants won’t change:
const int ledPin = 13; // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
// send the string “Knock!” back to the computer, followed by newline
Serial.println(“Knock!”);
}
delay(100); // delay to avoid overloading the serial port buffer
}
Um vídeo que mostra a construção na protoboard desse sketch (knock).
Construção do fluxograma do jogo VelhaBall.
Segue em anexo o fluxograma inicial do jogo VelhaBall, um ponto de partida geral para a programação de todos os estudantes do curso.
Construção do fluxograma
Nosso primeiro problema a resolver, para a construção do programa/sketch-arduino do jogo VelhaBall, será definir como o arduino fará a leitura dos nove sensores (cápsulas piezoelétricas ). Esses sensores indicarão em qual painel das matriz a bola bateu.
O exercício, em anexo, tem esse objetivo.
Bom trabalho!!!
02 – Construção do fluxograma
Digitação do programa Arduino que testa os nove sensores.