Anonymous avatar Anonymous committed 3cfcfc6

hackday2.pde -> senha.pde; adicionados pianinho.pde (AHD1) e turiquinhas.pde (AHD3)

Comments (0)

Files changed (4)

hackday2.pde

-# Este código foi escrito no II Arduino Hack Day
-# Está licenciado sob GPLv3:
-# Mais detalhes em: 
-
-const int RS = 3;
-const int RW = 4;
-const int E = 5;
-const int D[] = { 6, 7, 8, 9, 10, 11, 12, 13 };
-const int LED = 13;
-
-int fila = 0;
-int pinInputIncrement = 1;
-int pinSound = 0;
-
-int delay_enable = 5;
-
-void enable() {
-  delay(delay_enable);
-  digitalWrite(E, 0);
-  delay(delay_enable);
-  digitalWrite(E, 1);
-  delay(delay_enable);
-}
-
-void blink_LED(int t) {
-  digitalWrite(LED, 1);
-  delay(t);
-  digitalWrite(LED, 0);
-}
-
-void print_pins(char c) {
-  digitalWrite(D[7], ((int)c & 0x128) >> 7);
-  digitalWrite(D[6], ((int)c & 0x64) >> 6);
-  digitalWrite(D[5], ((int)c & 0x32) >> 5);
-  digitalWrite(D[4], ((int)c & 0x16) >> 4);
-  digitalWrite(D[3], ((int)c & 0x8) >> 3);
-  digitalWrite(D[2], ((int)c & 0x4) >> 2);
-  digitalWrite(D[1], ((int)c & 0x2) >> 1);
-  digitalWrite(D[0], (int)c & 0x1);
-}
-
-void setup_lcd() {
-  digitalWrite(RW, 0);
-  digitalWrite(RS, 0);
-  digitalWrite(E, 1);
-  
-  /* clean up the display */
-  print_pins(0x0C); /* 0x0F = 15 = 00001111 */
-  enable();
-  
-  /* enable two lines */
-  print_pins(0x3F); /* 0x3F = 63 = 00111111 */
-  enable();
-
-  /* enable two lines */
-  print_pins(128); /* move cursor to the 1st line */
-  enable();
-}
-
-void lcd_print(char *text) {
-  digitalWrite(RS, 1);
-  int size = 0, i;
-  while (text[size] != '\0') {
-    size++;
-  }
-  for (i = 0; i < size; i++) {
-    if (text[i] == '\n') {
-      digitalWrite(RS, 0);
-      print_pins(128 + 49 + 7); /* move cursor to the 2nd line */
-      enable();
-      digitalWrite(RS, 1);
-      delay(delay_enable);
-    }
-    else {
-      print_pins(text[i]);
-      enable();
-    }
-  }
-}
-
-
-void piscar_lcd(char *text){
-  setup_lcd();
-  lcd_print(text);
-  delay(100);
-  setup_lcd();
-  lcd_print("   ");
-  delay(50);
-  setup_lcd();
-  lcd_print(text);
-}
-
-
-void incrementa_fila(){
-  fila++;
-}
-
-void toca_nota(int freq, float time){
-  float delay_time = 1.0 / (freq * 2);
-  for (int i = 0; i < freq * time; i++){
-    digitalWrite(pinSound, HIGH);
-    delay(delay_time);
-    digitalWrite(pinSound, LOW);
-    delay(delay_time);
-  }
-}
-
-
-void setup() {
-  //
-  pinMode(pinInputIncrement, INPUT);
-  pinMode(pinSound, OUTPUT);
-  digitalWrite(pinInputIncrement, HIGH);
-
-  // LCD
-  int i;
-  blink_LED(100);
-  pinMode(RS, OUTPUT);
-  pinMode(RW, OUTPUT);
-  pinMode(E, OUTPUT);
-  for (i = 0; i < 8; i++) {
-    pinMode(D[i], OUTPUT);
-  }
-  pinMode(LED, OUTPUT);
-  
-  delay(1000);
-  setup_lcd();
-  lcd_print("Arduino Hackday");
-  delay(1000);
-  setup_lcd();
-  lcd_print("               ");
-}
-
-
-char fila_str[10];
-
-void loop() {
-  if (digitalRead(pinInputIncrement) == LOW){
-    incrementa_fila();
-    sprintf(fila_str, "%d", fila);
-    piscar_lcd(fila_str);
-    toca_nota(440, 1);
-  }
-}
-
+/*
+ * Copyright (C) 2009-2010 Álvaro Justen <alvaro@justen.eng.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 dated June, 1991.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * If you find any bugs or have any suggestions, please email me.
+ *
+ * This software was created on Arduino Hack Day (on 2009-12-) 
+ * See more details and authors at:
+ */
+
+const int buzzer = 2;
+int delay_microsec = 10000;
+int byte_lido = 0;
+int ligado = 0;
+
+#define LEDR 10
+#define LEDG 11
+#define LEDB 13
+
+#define BDO 9
+#define BRE 8
+#define BMI 7
+#define BFA 6
+#define BSOL 5
+#define BLA 4
+#define BSI 3
+#define BON 12
+
+#define DO 261
+#define DOs 277
+#define RE 293
+#define REs 311
+#define MI 329
+#define FA 349
+#define FAs 369
+#define SOL 391
+#define SOLs 415
+#define LA 440
+#define LAs 466
+#define SI 493
+#define DO2 523
+
+
+void setup()   {                
+  pinMode(buzzer, OUTPUT);
+  pinMode(BDO, INPUT);
+  pinMode(BRE, INPUT);
+  pinMode(BMI, INPUT);
+  pinMode(BFA, INPUT);
+  pinMode(BSOL, INPUT);
+  pinMode(BLA, INPUT);
+  pinMode(BSI, INPUT);
+  pinMode(BON, INPUT);
+
+  pinMode(LEDR, OUTPUT);
+  pinMode(LEDG, OUTPUT);
+  pinMode(LEDB, OUTPUT);
+  digitalWrite(LEDR, HIGH);
+  digitalWrite(LEDG, HIGH);
+  digitalWrite(LEDB, HIGH);
+
+  digitalWrite(BDO, HIGH);
+  digitalWrite(BRE, HIGH);
+  digitalWrite(BMI, HIGH);
+  digitalWrite(BFA, HIGH);
+  digitalWrite(BSOL, HIGH);
+  digitalWrite(BLA, HIGH);
+  digitalWrite(BSI, HIGH);
+  digitalWrite(BON, HIGH);
+  //Serial.begin(9600);
+}
+
+int nota_to_delay(int nota) {
+  return (1000000 / 2) / nota;
+}
+
+void loop() {
+  if (digitalRead(BDO) == LOW) {
+    delay_microsec = nota_to_delay(DO);
+    digitalWrite(LEDR, LOW);
+    ligado = 1;
+  }
+  else if (digitalRead(BRE) == LOW) {
+    delay_microsec = nota_to_delay(RE);
+    digitalWrite(LEDG, LOW);
+    ligado = 1;
+  }
+  else if (digitalRead(BMI) == LOW) {
+    delay_microsec = nota_to_delay(MI);
+    digitalWrite(LEDB, LOW);
+    ligado = 1;
+  }
+  else if (digitalRead(BFA) == LOW) {
+    delay_microsec = nota_to_delay(FA);
+    ligado = 1;
+    digitalWrite(LEDR, HIGH);
+  }
+  else if (digitalRead(BSOL) == LOW) {
+    delay_microsec = nota_to_delay(SOL);
+    ligado = 1;
+    digitalWrite(LEDG, HIGH);
+  }
+  else if (digitalRead(BLA) == LOW) {
+    delay_microsec = nota_to_delay(LA);
+    ligado = 1;
+    digitalWrite(LEDB, HIGH);
+  }
+  else if (digitalRead(BSI) == LOW) {
+    delay_microsec = nota_to_delay(SI);
+    ligado = 1;
+    digitalWrite(LEDR, HIGH);
+    digitalWrite(LEDG, HIGH);
+    digitalWrite(LEDB, HIGH);
+  }
+  else {
+    ligado = 0;
+    //digitalWrite(LEDR, HIGH);
+    //digitalWrite(LEDG, HIGH);
+    //digitalWrite(LEDB, HIGH);
+  }
+
+  if (digitalRead(BON) == LOW) {
+    ligado = 0;
+  }
+
+  if (ligado == 1) {
+    analogWrite(buzzer, 255);
+    delayMicroseconds(delay_microsec);
+    analogWrite(buzzer, 0);
+    delayMicroseconds(delay_microsec);
+  }
+  /*
+  if (Serial.available() > 0) {    
+    byte_lido = Serial.read();
+    if (byte_lido >= '0' && byte_lido <= '9') {
+      switch (byte_lido) {
+        case '1':
+          Serial.println("Do");
+          break;
+        case '2':
+          delay_microsec = nota_to_delay(RE);
+          Serial.println("Re");
+          break;
+        case '3':
+          delay_microsec = nota_to_delay(MI);
+          Serial.println("Mi");
+          break;        
+        case '4':
+          delay_microsec = nota_to_delay(FA);
+          Serial.println("Fa");
+          break;
+        case '5':
+          delay_microsec = nota_to_delay(SOL);
+          Serial.println("Sol");
+          break;
+        case '6':
+          delay_microsec = nota_to_delay(LA);
+          Serial.println("La");
+          break;
+        case '7':
+          delay_microsec = nota_to_delay(SI);
+          Serial.println("Si");
+          break;
+        case '8':
+          delay_microsec = nota_to_delay(DO2);
+          Serial.println("Do2");
+          break;
+      }
+      ligado = 1;
+    }
+    else {
+      ligado = 0;
+    }
+  }
+  */
+}
+/*
+ * Copyright (C) 2010 Álvaro Justen <alvaro@justen.eng.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 dated June, 1991.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * 
+ * If you find any bugs or have any suggestions, please email me.
+ *
+ * This software was created on Arduino Hack Days (on 2010-03-28 and 2010-04-01)
+ * See more details and authors at: 
+ * http://blog.justen.eng.br/2010/03/arduino-hack-n-beer-sunday.html
+ * http://blog.justen.eng.br/2010/03/arduino-hack-n-beer-sunday-foi.html
+ * http://blog.justen.eng.br/2010/03/arduino-hack-n-beer-day-reloaded.html
+ * 
+ */
+
+
+//1 -> VSS
+//2 -> VCC
+const int RS = 3;
+const int RW = 4;
+const int E = 5;
+const int D[] = { 6, 7, 8, 9, 10, 11, 12, 13 };
+const int LED = 13;
+//15 - > LED+
+//16 - > LED-
+
+int fila = 0;
+int pinInputIncrement = 1;
+int pinInputRepeat = 2;
+int pinSound = 0;
+
+int delay_enable = 5;
+
+void enable() {
+  delay(delay_enable);
+  digitalWrite(E, 0);
+  delay(delay_enable);
+  digitalWrite(E, 1);
+  delay(delay_enable);
+}
+
+void blink_LED(int t) {
+  digitalWrite(LED, 1);
+  delay(t);
+  digitalWrite(LED, 0);
+}
+
+void print_pins(char c) {
+  digitalWrite(D[7], ((int)c & 0x128) >> 7);
+  digitalWrite(D[6], ((int)c & 0x64) >> 6);
+  digitalWrite(D[5], ((int)c & 0x32) >> 5);
+  digitalWrite(D[4], ((int)c & 0x16) >> 4);
+  digitalWrite(D[3], ((int)c & 0x8) >> 3);
+  digitalWrite(D[2], ((int)c & 0x4) >> 2);
+  digitalWrite(D[1], ((int)c & 0x2) >> 1);
+  digitalWrite(D[0], (int)c & 0x1);
+}
+
+void setup_lcd() {
+  digitalWrite(RW, 0);
+  digitalWrite(RS, 0);
+  digitalWrite(E, 1);
+  
+  /* clean up the display */
+  print_pins(0x0C); /* 0x0F = 15 = 00001111 */
+  enable();
+  
+  /* enable two lines */
+  print_pins(0x3F); /* 0x3F = 63 = 00111111 */
+  enable();
+
+  /* enable two lines */
+  print_pins(128); /* move cursor to the 1st line */
+  enable();
+}
+
+void lcd_print(char *text) {
+  digitalWrite(RS, 1);
+  int size = 0, i;
+  while (text[size] != '\0') {
+    size++;
+  }
+  for (i = 0; i < size; i++) {
+    if (text[i] == '\n') {
+      digitalWrite(RS, 0);
+      print_pins(128 + 49 + 7); /* move cursor to the 2nd line */
+      enable();
+      digitalWrite(RS, 1);
+      delay(delay_enable);
+    }
+    else {
+      print_pins(text[i]);
+      enable();
+    }
+  }
+}
+
+
+void piscar_lcd(char *text){
+  setup_lcd();
+  lcd_print(text);
+  delay(100);
+  setup_lcd();
+  lcd_print("   ");
+  delay(50);
+  setup_lcd();
+  lcd_print(text);
+}
+
+
+void toca_nota(int freq, float time){
+  float delay_time = 1000000.0 / (freq);
+  float delay_time1 = 0.9 * delay_time;
+  float delay_time2 = 0.1 * delay_time;
+  for (int i = 0; i < freq * time; i++){
+      digitalWrite(pinSound, HIGH);
+      delayMicroseconds(delay_time2);
+      digitalWrite(pinSound, LOW);
+      delayMicroseconds(delay_time1);
+  }
+}
+
+
+void vem_ca_filho_da_puta(int senha){
+    char senha_str[10];
+    sprintf(senha_str, "%d", senha);
+    piscar_lcd(senha_str);
+    toca_nota(1720, 1);
+    toca_nota(880, 1);
+}
+
+void setup() {
+  // Define o botão de input para o próximo número 
+  // como input e coloca 5v nele (por causa do pullup
+  // resistor
+  pinMode(pinInputIncrement, INPUT);
+  digitalWrite(pinInputIncrement, HIGH);
+  
+  // Faz o mesmo para o pino de repetição do número
+  pinMode(pinInputRepeat, INPUT);
+  digitalWrite(pinInputRepeat, HIGH);
+  
+  pinMode(pinSound, OUTPUT);
+
+  // Prepara o LCD
+  int i;
+  blink_LED(100);
+  pinMode(RS, OUTPUT);
+  pinMode(RW, OUTPUT);
+  pinMode(E, OUTPUT);
+  for (i = 0; i < 8; i++) {
+    pinMode(D[i], OUTPUT);
+  }
+  pinMode(LED, OUTPUT);
+  
+  // Faz uma pequena apresentação
+  delay(1000);
+  setup_lcd();
+  lcd_print("Arduino Hackday");
+  delay(1000);
+  setup_lcd();
+  lcd_print("               ");
+}
+
+
+
+void loop() {
+  if (digitalRead(pinInputIncrement) == LOW){
+    fila++;
+    vem_ca_filho_da_puta(fila);
+  } else if (digitalRead(pinInputRepeat) == LOW) {
+    vem_ca_filho_da_puta(fila);
+  }
+}
+
+/*
+ * Copyright (C) 2010 Álvaro Justen <alvaro@justen.eng.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 dated June, 1991.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * If you find any bugs or have any suggestions, please email me.
+ *
+ * This software was created on Arduino Hack Day Reloaded (2010-04-01) 
+ * See more details and authors at:
+ * http://blog.justen.eng.br/2010/03/arduino-hack-n-beer-day-reloaded.html
+ * 
+ */
+
+#define FREQ_ANTI 250
+#define FREQ 128
+
+int sensorValorEsq;
+int sensorValorDir;
+int sensorValorFrente;
+int sensorValorTras;
+int potenciometro;
+#ifdef DEBUG
+char enviar[10];
+#endif
+
+const int PinRodaDir = 6;
+const int PinRodaEsq = 7;
+const int pinPotenciometro = 10;
+const int ledPinDir = 8;
+const int ledPinEsq = 9;
+const int ledPinStopped = 10;
+const int buzzer = 11;
+const int analogInDir = 6;
+const int analogInEsq = 7;
+const int analogInFrente = 8;
+const int analogInTras = 9;
+
+void startEsquerda() {
+  analogWrite(PinRodaEsq, FREQ_ANTI);
+}
+
+void startDireita() {
+  analogWrite(PinRodaDir, FREQ);
+}
+
+void trasDireita() {
+  analogWrite(PinRodaDir, FREQ_ANTI);
+}
+void trasEsquerda() {
+  analogWrite(PinRodaEsq, FREQ);
+}
+
+void stopDireita() {
+    analogWrite(PinRodaDir, 0);
+}
+
+void stopEsquerda() {
+    analogWrite(PinRodaEsq, 0);
+}
+
+void setup() {
+  pinMode(PinRodaEsq, OUTPUT);  
+  pinMode(PinRodaDir,OUTPUT);
+  pinMode(ledPinDir,OUTPUT);
+  pinMode(ledPinEsq,OUTPUT);
+  pinMode(ledPinStopped,OUTPUT);
+  analogWrite(buzzer, 0);
+
+  stopDireita();
+  stopEsquerda();
+  #ifdef DEBUG
+  Serial.begin(9600);
+  #endif
+}
+
+void loop() {
+  potenciometro = analogRead(pinPotenciometro);
+  
+  sensorValorEsq = analogRead(analogInEsq);
+  sensorValorDir = analogRead(analogInDir);
+  sensorValorFrente = analogRead(analogInFrente);
+  sensorValorTras = analogRead(analogInTras);
+  
+  int diff = sensorValorEsq - sensorValorDir;
+  
+  if (sensorValorFrente >= potenciometro) {
+    startDireita();
+    startEsquerda();
+    analogWrite(buzzer, 0);
+    digitalWrite(ledPinStopped, HIGH);
+    digitalWrite(ledPinEsq, LOW);
+    digitalWrite(ledPinDir, LOW);
+  }
+  else if (sensorValorTras >= potenciometro) {
+    trasDireita();
+    trasEsquerda();
+    analogWrite(buzzer, 128);
+    digitalWrite(ledPinStopped, LOW);
+    digitalWrite(ledPinEsq, LOW);
+    digitalWrite(ledPinDir, LOW);
+  }
+  else if (sensorValorEsq >= potenciometro) {
+    startEsquerda();
+    stopDireita();
+    analogWrite(buzzer, 0);
+    digitalWrite(ledPinStopped, HIGH);
+    digitalWrite(ledPinEsq, HIGH);
+    digitalWrite(ledPinDir, LOW);
+  }
+  else if (sensorValorDir >= potenciometro) {
+    stopEsquerda();
+    startDireita();
+    analogWrite(buzzer, 0);
+    digitalWrite(ledPinStopped, HIGH);
+    digitalWrite(ledPinEsq, LOW);
+    digitalWrite(ledPinDir, HIGH);
+  }
+  else {
+    stopDireita();
+    stopEsquerda();
+    analogWrite(buzzer, 0);
+    digitalWrite(ledPinStopped, HIGH);
+    digitalWrite(ledPinEsq, LOW);
+    digitalWrite(ledPinDir, LOW);
+  }
+
+  #ifdef DEBUG
+  sprintf(enviar, "%04d %04d", sensorValorEsq, sensorValorDir);
+  Serial.println(enviar);
+  #endif
+  
+  //delay(100);
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.