Outils pour utilisateurs

Outils du site


interface_lego_dacta_70909

Ceci est une ancienne révision du document !


Interface LEGO dacta 70909

Matériel

  • Interface série LEGO 2954
  • Adaptateur USB/Série Chipi-X
  • Câble série Male/femelle LEGO 9768
  • Transformateur LEGO 70931
  • Sirène 9V LEGO 4774c01

Processing

import processing.serial.*;
 
Serial portSerie;
Bouton[] boutons;
 
int val;
boolean connexion;
String init = "";
 
void setup() {
  size(400, 400);
  noStroke();
  portSerie = new Serial(this, "/dev/cu.usbserial-FT1MGSG5", 9600);
  String message = "p\0###Do you byte, when I knock?$$$";
  portSerie.write(message);
  connexion = false;
  color c = color(255, 0, 0);
  boutons = new Bouton[2];
  boutons[0] = new Bouton(new PVector(50, 100), new PVector(100, 100), color(255, 0, 0));
  boutons[1] = new Bouton(new PVector(250, 100), new PVector(100, 100), color(255, 0, 0));
 
  int valeur = 0b00100001;
  thread("maintenirConnexion");
}
 
void draw() {
  background(255);
  if (!connexion) {
    if  (init.length() < 31) {
      while (portSerie.available() > 0) {
        String inBuffer = portSerie.readString();   
        if (inBuffer != null) {
          init += inBuffer;
        }
      }
    } else {
      if (init.equals("###Just a bit off the block!$$$")) {
        connexion = true;
        println(init);
      } else {
        init = "";
        String message = "p\0###Do you byte, when I knock?$$$";
        portSerie.write(message);
      }
    }
  }
for (Bouton b : boutons) {
    b.dessiner();
  }
}
 
void mousePressed() {
  for (Bouton b : boutons) {
    b.cliquer();
  }
  if (boutons[0].actif) {
    portSerie.write(0x10);
  }
  if (boutons[1].actif) {
    portSerie.write(0x18);
  }
}
 
void mouseReleased() {
  for (Bouton b : boutons) {
    b.relacher();
  }
  portSerie.write(0x90);
  portSerie.write(0xFF);
 
}
 
void keyPressed() {
  if (key == 'a') {
    for (int i = 0; i < 8; i++) {
      portSerie.write(0x10 + i);
      delay(500);
      portSerie.write(0x30 + i);
    }
  }
  if (key == 'z') {
    for (int i = 0; i < 8; i++) {
      portSerie.write(0x18 + i);
      delay(500);
      portSerie.write(0x30 + i);
    }
  }
}
 
void maintenirConnexion() {
  int tempsInit = millis();
  while (true) {
    if ((millis() - tempsInit) > 2000) {
      tempsInit = millis();
      portSerie.write(0x02);
    }
  }
}
 
class Bouton {
  PVector position, taille;
  color couleur;
  boolean actif;
 
  Bouton(PVector p, PVector t, color c) {
    position = p;
    taille = t;
    couleur = c;
  }
 
  void dessiner() {
    noStroke();
    if (actif) {
      fill(color(150, 50, 50));
    } else {
      fill(couleur);
    }
    rect(position.x, position.y, taille.x, taille.y, 10);
  }
 
  void cliquer() {
    if ((mouseX > position.x) && (mouseX < position.x + taille.x) && (mouseY > position.y) && (mouseY < position.y + taille.y)) {
      actif = true;
    }
  }
 
  void relacher() {
    actif = false;
  }
}

Utilisation

La sirène à deux types de sons, pour en changer il suffit de tourner le dessus. Afin de tester placer la sirène sur l'emplacement On. Tourner la partie supérieure pour entendre le son.

Placer ensuite la sirène sur le port A et lancer le programme. Appuyer alternativement sur les zones rouges à l'écran pour entendre les deux sons disponibles.

Pour poursuivre l'exploration, vous pouvez consulter les liens ci-dessous.

Ressources

interface_lego_dacta_70909.1586874603.txt.gz · Dernière modification : 2020/04/14 14:30 de Mushussu