====== Interface LEGO dacta 70909 ====== ===== Matériel ===== * Interface série LEGO [[https://www.bricklink.com/v2/catalog/catalogitem.page?id=10760#T=C&C=10|2954]] * Adaptateur USB/Série [[https://www.ftdichip.com/Support/Documents/DataSheets/Cables/DS_Chipi-X.pdf|Chipi-X]] * Câble série Male/femelle LEGO [[https://www.bricklink.com/v2/catalog/catalogitem.page?S=9768-1|9768]] * Transformateur LEGO [[https://www.bricklink.com/v2/catalog/catalogitem.page?P=70931#T=C&C=11|70931]] * Sirène 9V LEGO [[https://www.bricklink.com/v2/catalog/catalogitem.page?P=4774c01#T=C|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 ===== * [[http://www.timo.dk/wp/2009/01/25/java-control-class-for-dacta-70909/|JAVA control class for DACTA 70909]] * [[http://www.blockcad.net/dacta/The Lego DACTA computer interface 70909]] * [[http://www.lgauge.com/technic/LEGOInterfaceB/9751.htm|9751 LEGO Technic Interface B]] {{tag>LEGO processing sylvain}}