0 Members and 3 Guests are viewing this topic.
Si on paramètre le COM par l'invite de commande DOS, doit on le faire avec Lua?
J'ai continué mes investigations sur ces résistances en parallèle.J'ai mis au point un algorithme qui calculait la résistance insérée(ou retirée)en fonction de la variation de tension mesurée à A0. Ça marchait bien pour3 switches différents, mais quand j'en ai mis 8, et que je les mettais tousà 1, il y avait trop de dérive pour pouvoir faire des calculs précis. Donc, pour moi, c'était une impasse technique.
int Vprecedent;int Vlue; /Valeur lue en A0long Req; //Résistance équivalentelong R1; //Ancienne résistance équivalentelong R2; //Valeur de résistance insérée(ou désinsérée) byte Nb_switches_on=0; //Nombre de switches sur "ON"byte Prev_nb_switches_on=0; //Nombre de switches sur "ON", précédentvoid setup() { Serial.begin(9600);}void loop() { Vlue = analogRead(A0); if ((Vlue>Vprecedent+3) && (Nb_switches_on==0)) { //Cas du premier switch mis sur "ON" Nb_switches_on=1; Req=((1023*98)/Vlue)-98 //Calcul de la résistance associée au switch manoeuvré. La valeur de 98 correspond à la valeur précise R1=Req; // en Ohms de la résistance se trouvant entre A0 et GND. 1023 correspond à la "définition" de A0 R2=R1; Vprecedent=Vlue; Serial.println("Cas du premier switch mis sur ON"); Serial.println(R1); Serial.println(Vlue); } else if ((Vlue>Vprecedent+3) && (Nb_switches_on>=0)) { //Cas d'un switch supplémentaire mis sur "ON" Nb_switches_on=Nb_switches_on+1; Req=((1023*98)/Vlue)-98; //Calcul de la résistance associée au switch manoeuvré R2=(R1*Req)/(R1-Req); R1=Req; Serial.println("Cas d'un switch spplémentaire mis sur ON"); Serial.println(R2); Serial.println(Vlue); Vprecedent=Vlue; } else if (Vlue<Vprecedent-3 && Nb_switches_on>1) { //Cas d'un switch mis sur OFF et il reste au moins 1 switch sur "ON" Nb_switches_on=Nb_switches_on-1; Req=((1023*98)/Vlue)-98; R2=-(R1*Req)/(R1-Req); //Calcul de la résistance retranchée R1=Req; Vprecedent=Vlue; Serial.println("Cas d'un switch spplémentaire mis sur OFF"); Serial.println(R2); Serial.println(Vlue); } else if ((Vlue<Vprecedent-3) && (Nb_switches_on==1)) { //Cas du dernier switch mis sur "OFF " Nb_switches_on=Nb_switches_on-1; Req=0; R2=R1; R1=0; Vprecedent=Vlue; Serial.println("Cas du premier switch mis sur OFF"); Serial.println(R2); Serial.println(Vlue); } if (Prev_nb_switches_on != Nb_switches_on) //Ici, début de la scrutation afin de connaître la valeur de résistance insérée ou retranchée { if ((R2>220) &&(R2<230)) { Serial.println("Envoyer 3° commut"); //Par exemple, 3° commut, qui aurait eu un keyboard.pressKey(key) } Serial.println("Mouvement de swich"); Prev_nb_switches_on=Nb_switches_on; }delay(100); }
Là où je bute, c'est dans les paths dans Lua (pardon, vslash, je fais mon possible) Lua est assez exotique par bien des aspects pour moi.
note = oapi.create_annotation()note:set_pos (0.35,0.1,0.8,0.95)note:set_colour ({r=0.9,g=0.5,b=0.2})intro = "Essai de luars232"note:set_text(intro) --Affichage à l'écranproc.wait_sysdt(1.0)rs232=require("luars232") --le fameux "require"local port_name="COM4" --Port sur lequel la Uno est branchéelocal e,p=rs232.open(port_name) --Ouverture du port COM4if e ~= rs232.RS232_ERR_NOERROR then term.out('',string.format("can't open serial port '%s', error: '%s'\n", port_name, rs232.error_tostring(e))) returnend-- set port settingsassert(p:set_baud_rate(rs232.RS232_BAUD_9600) == rs232.RS232_ERR_NOERROR)assert(p:set_data_bits(rs232.RS232_DATA_8) == rs232.RS232_ERR_NOERROR)assert(p:set_parity(rs232.RS232_PARITY_NONE) == rs232.RS232_ERR_NOERROR)assert(p:set_stop_bits(rs232.RS232_STOP_1) == rs232.RS232_ERR_NOERROR)assert(p:set_flow_control(rs232.RS232_FLOW_OFF) == rs232.RS232_ERR_NOERROR)err, len_written = p:write("U") --écrire "U", soit chr$(85),vers la Uno. 85 en binaire, c'est 01010101. C'est le coeur du script.note:set_text('Longueur Ècrite='..len_written)proc.wait_sysdt(1)assert(p:close() == rs232.RS232_ERR_NOERROR) -- this closes the COMnote:set_text('End of program')proc.wait_sysdt(1)note:set_text(' ')proc.wait_sysdt(1)
int dataPin=2; //Pin 2 branché sur la patte 14 (DS)int latchPin=3; //Pin 3 branché sur la patte 12 (ST_CP) c'est le LATCHint clockPin=4; //Pin 4 branché sur la patte 11 (SH_CP)=>CLKint i=0;int data=255; // Avec data=255, allumage des 8 LED.void setup() { pinMode (dataPin,OUTPUT); pinMode (latchPin,OUTPUT); pinMode (clockPin,OUTPUT); Serial.begin(9600); } void loop(){ for (i=0 ; i<=13 ; i++) //Cette boucle est un vestige du sketch utilisé pour faire celui-ci { if (Serial.available()>0) //Si quelque chose arrive sur le port.... { data=Serial.read(); //Lire ce quelque chose } digitalWrite(latchPin,LOW); //Registre en remplissage shiftOut(dataPin, clockPin, LSBFIRST, data); //Remplir registre avec data (8 bits) digitalWrite(latchPin, HIGH); //Registre en affichage=>LED allumées en fonction de la valeur data delay(150); }}
Alors, là, c'est à moi de demander: c'est quoi, asta? American Spice Trade Association?Association Sportive des Toujours Actifs?American Society of Travel Agents?
De Nulentout: C'EST A SE TAPER LE CUL PAR TERRE !
-- A giant leap for a man, a small step for mankind!!note = oapi.create_annotation()note:set_pos (0.35,0.1,0.8,0.95)note:set_colour ({r=0.9,g=0.5,b=0.2})intro = "Machmètre sur 2 displays 7 segments"note:set_text(intro)proc.wait_sysdt(1.0)v=vessel.get_interface('XR2-01')rs232=require("luars232")local port_name="COM4"local e,p=rs232.open(port_name)if e ~= rs232.RS232_ERR_NOERROR then term.out('',string.format("can't open serial port '%s', error: '%s'\n", port_name, rs232.error_tostring(e))) returnend-- set port settingsassert(p:set_baud_rate(rs232.RS232_BAUD_9600) == rs232.RS232_ERR_NOERROR)assert(p:set_data_bits(rs232.RS232_DATA_8) == rs232.RS232_ERR_NOERROR)assert(p:set_parity(rs232.RS232_PARITY_NONE) == rs232.RS232_ERR_NOERROR)assert(p:set_stop_bits(rs232.RS232_STOP_1) == rs232.RS232_ERR_NOERROR)assert(p:set_flow_control(rs232.RS232_FLOW_OFF) == rs232.RS232_ERR_NOERROR)repeat alt=oapi.get_altitude() mach = v:get_machnumber() mach_display=math.floor(10*mach) hundred=math.floor(mach_display/100) mach_display=mach_display-100*hundred ten=math.floor(mach_display/10) mach_display=mach_display-10*ten unit=mach_display byte1=unit+16*ten byte2=hundred note:set_text(byte2.." "..byte1.." "..hundred..ten..unit) if unit~=old_unit then err, len_written = p:write(string.char(byte2)..string.char(byte1)) end old_unit=unit proc.skip()until alt>10000 --On sort si l'altitude >10000 mètres. Il faut sortir "proprement", sinon --plus moyen d'utiliser le port COM4 à moins de faire un arrêt-redémarrage --de l'ordinateurnote:set_text('Longueur Ecrite='..len_written)proc.wait_sysdt(1)assert(p:close() == rs232.RS232_ERR_NOERROR)-- this closes the COMnote:set_text('End of program')proc.wait_sysdt(1)note:set_text(' ')proc.wait_sysdt(1)
int dataPin=2;int latchPin=3;int clockPin=4;int data=255;byte octet1;byte octet2;void setup() { pinMode (dataPin,OUTPUT); pinMode (latchPin,OUTPUT); pinMode (clockPin,OUTPUT); Serial.begin(9600); } void loop(){ if (Serial.available()>0) { octet1=Serial.read(); octet2=Serial.read(); digitalWrite(latchPin,LOW); shiftOut(dataPin, clockPin, LSBFIRST, octet1); shiftOut(dataPin, clockPin, LSBFIRST, octet2); digitalWrite(latchPin, HIGH); } delay(150);}
si (route+180)%360 > cap : vire à droitesinon : vire à gauche
si (route - dest)%360 > 180 : vire à droitesinon : vire à gauche
si route - dest < 0 : si route - dest + 360 > 180 : vire à droite sinon : vire à gauchesinon : si route - dest > 180 : vire à droite sinon : vire à gauche