Boas pessoal, decidi partilhar por aqui alguns tutoriais que criei em inglês para tornar o conteúdo mais abrangente em todo o mundo.
Hoje tenho presentes cinco vídeos no Youtube desde maio de 2014 e o canal já obteve 775 visualizações em 63 países. Que me dá ânimo para continuar a aprofundar a minha aprendizagem em linguagem de programação Python.
Desde já vou apresentar os vídeos que partilhei no Youtube, e em todos eles está o diagrama de circuitos usado bem como o link para fazer download do script editado em Python.
3 LED control input Python script for Raspberry Pi GPIO
Guess the magic number python script for controlling LEDs with Raspberry Pi GPIO
LED reaction for input of a integer checking perfect cube root Python script using Raspberry Pi GPIO
Sequential logic game/test in Raspberry Pi GPIO Python
Seasons of the year learning using simple inputs with Python and Raspberry Pi GPIO
Os dois últimos tutorias partilhados aqui foram criados com o intuito de poder criar baterias pedagógicas e testes neuropsicológicos em crianças com Autismo de Kanner e Síndrome de Asperger, tentanto ensinar a essas crianças sistemas sequenciais simples como no primeiro caso um sistema biestável, e no segundo, um sistema sequencial que pudesse através da apliacação de testes se as crianças conseguiriam aprender a sequência das estações do ano.
De facto, o primeiro dos testes que apresentei foram anteriormente criados em Arduino, devido ao projecto da disciplina de Electrónica Analógica, ao qual montei um circuito, mais ou menos simples para aplicar os testes em crianças com Autismo com a gentil ajuda da APPDA Setúbal (Associação Portuguesa para as Pertubações de Desenvolvimento e Autismo).
Para a edição, compilação e ambiente gráfico para correr os programas em Arduino precisam
de usar o IDE Arduino, disponível para download grátis em
http://arduino.cc/en/Main/Software
Podemos ver primeiramente o código em linguagem C/C++:
de usar o IDE Arduino, disponível para download grátis em
http://arduino.cc/en/Main/Software
Podemos ver primeiramente o código em linguagem C/C++:
//This script was written to make a user understand the meaning of sequential
//logic. The combination of different inputs gives a certain output.
//A constant output(RED LED) is given as the program starts, and by trying
//different inputs the user is asked to reach a different constant
//output(GREEN LED) by using the inputs learned.
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#include <LiquidCrystal.h>
const int buttonPin = 13; //Defining variable names for each input and output
const int buttonPin2 = 9;
const int redLed = 6;
const int greenLed = 10;
int buttonState = 0; //Defining logic state of each input
int buttonState2 = 0;
int count = 0; //Defining number of pressed inputs
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3, NOTE_B3, NOTE_C4};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] =
{
4, 8, 8, 4,4,4,3,4 };
// initialize the library with the numbers of the interface pins
void setup()
{
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(redLed, OUTPUT); //RED LED
pinMode(greenLed, OUTPUT); // GREEN LED
lcd.begin(16, 2); //set up the LCD's number of columns and rows
lcd.print("START TEST!");
delay(2000);
lcd.clear();
}
void loop() {
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
{
//read the pushbutton value into a variable
int sensorVal = digitalRead(buttonPin);
int sensorVal2 = digitalRead(buttonPin2);
//print out the value of the pushbutton
if (sensorVal == HIGH && sensorVal2 == HIGH) {
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
lcd.setCursor(0, 0);
lcd.print("CIRCUIT OFF");
delay(500);
lcd.clear();
}
if (sensorVal == LOW && sensorVal2 == LOW){
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
delay(2000);
for (int thisNote = 0; thisNote < 7; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote]; //Melody for alerting the tester that the game or test is complete
tone(7, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(7);
}
lcd.setCursor(0, 0);
lcd.print("TEST COMPLETE"); //Moment when both inputs are pressed and the test is finished
delay(5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time of test:");
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
lcd.print(" seconds");
delay(15000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Number of tries:");
lcd.setCursor(0, 1);
lcd.print(count++);
lcd.print(" times");
exit(0);
}
if ((sensorVal == LOW && sensorVal2 == HIGH) && (buttonState == LOW && buttonState2 == HIGH)) //Declaration of if fuction using two AND statements
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
lcd.setCursor(0, 0);
lcd.print("CIRCUIT ON");
count++;
delay(500);
lcd.clear();
}
if ((sensorVal == HIGH && sensorVal2 == LOW) && (buttonState == HIGH && buttonState2 == LOW)) //Declaration of if fuction using two AND statements
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
delay(500);
lcd.setCursor(0, 0);
count++;
lcd.print("RESET");
delay(500);
lcd.clear();
}
}
}
Podemos também olhar para o digrama de circuitos do printscreen feito no software Frizing
A foto do circuito montado:
E finalmente foi criado um aparelho simples para ser testado nas crianças,
que decorreu nas instalações da APPDA da Quinta do Conde
Sequenciador
de LEDs comandado por serial com LCD 2x16 normal e Arduino
Como projecto indicado para cumprir na disciplina de Microcontroladores foi-nos
pedido para criar em arduíno um sequenciador de LEDs controlado por comandos de
série. Criei um código para a introdução de strings em consola de série por
linguagem natural. Espero que gostem. Aqui fica o vídeo de demonstração:
O código em C/C++:
//Sequenciador de LEDs com comandos serie e LCD
#include <LiquidCrystal.h> //Biblioteca de LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(6, OUTPUT); //LEDS
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
lcd.begin(16,2);
lcd.print("SEQUENCIADOR");
delay(5000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Escolha a ");
lcd.setCursor(0, 1);
lcd.print(" sequencia");
delay(3000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("No monitor ");
lcd.setCursor(0, 1);
lcd.print(" de serie");
delay(3000);
lcd.clear();
Serial.begin(9600); //
Serial.flush();
}
void loop()
{
String input = "";
// Ler qualquer input no monitor de serie
while (Serial.available() > 0)
{
input += (char) Serial.read(); //Ler um caracater de cada vez
delay(5); // Delay de 5 milisegungos para a entrada de cada letra
}
if (input == "ligar")
{
lcd.setCursor(0, 1);
lcd.print("LIGADO");
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(3000);
lcd.clear();
}
if (input == "desligar")
{
lcd.setCursor(0, 1);
lcd.print("DESLIGADO");
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
delay(3000);
lcd.clear();
}
if (input == "piscar")
{
lcd.setCursor(0, 1);
lcd.print("PISCAR");
digitalWrite(6,HIGH);
delay(500);
digitalWrite(6,LOW);
delay(500);
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
digitalWrite(8,HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
digitalWrite(9,HIGH);
delay(500);
digitalWrite(9, LOW);
delay(3000);
lcd.clear();
}
if (input == "kit")
{
lcd.setCursor(0, 1);
lcd.print("KIT");
digitalWrite(6,HIGH);
delay(200);
digitalWrite(6,LOW);
delay(25);
digitalWrite(7,HIGH);
delay(100);
digitalWrite(7,LOW);
delay(25);
digitalWrite(8,HIGH);
delay(100);
digitalWrite(8,LOW);
delay(25);
digitalWrite(9,HIGH);
delay(100);
digitalWrite(9,LOW);
delay(25);
digitalWrite(9,HIGH);
delay(100);
digitalWrite(9,LOW);
delay(25);
digitalWrite(8,HIGH);
delay(100);
digitalWrite(8,LOW);
delay(25);
digitalWrite(7,HIGH);
delay(100);
digitalWrite(7,LOW);
delay(25);
digitalWrite(6,HIGH);
delay(100);
digitalWrite(6,LOW);
delay(25);
delay(3000);
lcd.clear();
}
if (input == "seq1")
{
lcd.setCursor(0, 1);
lcd.print("SEQUENCIA 1");
digitalWrite(6, HIGH);
delay(500);
digitalWrite(7, HIGH);
delay(500);
digitalWrite(8, HIGH);
delay(500);
digitalWrite(9, HIGH);
delay(500);
digitalWrite(6, LOW);
delay(500);
digitalWrite(7, LOW);
delay(500);
digitalWrite(8, LOW);
delay(500);
digitalWrite(9, LOW);
delay(500);
delay(3000);
lcd.clear();
}
if (input == "seq2")
{
lcd.setCursor(0, 1);
lcd.print("SEQUENCIA 2");
digitalWrite(6, HIGH);
digitalWrite(9, HIGH);
delay(500);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
delay(500);
digitalWrite(6, LOW);
digitalWrite(9, LOW);
delay(500);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
delay(500);
delay(3000);
lcd.clear();
}
}
Diagrama de circuitos em software Fritzing:
Obrigado!


