dimanche 17 août 2014

calculer la résistance:

Panoramic calcul la résistance "X" d'un diviseur de tension  aux bornes d'une entrée analogique d'une carte "Arduino".
Comme échantillonnage et de 1024 bits la précision n'est pas au rendez-vous.
On peut changer la résistance de "1 k" pour moduler les plages de calcul.
 On utilise toujours la " IO_Acces_COM.dll " pour la "com série".


Code
error_french
width 0,1000:color 0,160,160,200:wait 20
caption 0,"Panoramic et Arduino Uno"
top 0,(screen_y-height(0))/2 :left 0,(screen_x-width(0))/2
dim i,division%,div,nobj,com_ok,a%,a1%,aa%,dat%,donner$, poubele$,tension
dim vr1,ir,rt,rx%
label sp_fin,sp_com_on,sp_reception,sp_Mesure,sp_stop_com
label calcul_resistance
alpha 1
nobj=10: affichtxt(nobj,0,10,width(0)-250,16," PANORAMIC ")
nobj=20 :affichtxt(nobj,0,120,455,20," OHMS "):color 20,220,220,200
 font_name  20,constantia
nobj=30: voyant_automate(nobj,0,120,200,"COM",0)
nobj=40: button_container(nobj,0,220,590,"F I N")
nobj=50: button_container(nobj,0,220,150,"Com On")
nobj=60: button_container(nobj,0,220,250,"Com Off")
nobj=70: affichtxt(nobj,0,250,width(0)-250,86," W"):font_name  71,"Symbol"
nobj=80: button_container(nobj,0,220,455,"Mesure")
nobj=90: affichtxt(nobj,0,10,50,16," Mesure de résistance ")
nobj=120 :affichtxt(nobj,0,120,left(20)+width(20),20,"  W  ")
color 120,220,220,200:font_name  121,"Symbol"
on_click 41,sp_fin
on_click 51,sp_com_on
on_click 61,sp_stop_com
on_click 81,sp_Mesure
' ====================
    end : ' ==========
' ====================
rem #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
 ' ====Fin============
sp_fin:

 terminate
return
' ====================
sp_com_on:
if com_ok=0
com_serie()
end_if
return

' ====================
sub com_serie()
 dim_local rc,rrc
 rem #########################################################
 rem ##### DLL chargée en mémoire  suivant configuration 
 rem #########################################################
 dll_on "c:\dll_Panoramic\IO_Acces_COM.dll"
 rc= dll_call1("ComUsePort",8)
 if rc=1
    rrc= dll_call4("ComConfig",115200,8,1,0)
 end_if
 if rc=1 and rrc=1
    com_ok =1
    position 32,1 :inactive 51: hide 40
 else
    rc= dll_call1("ComUsePort",0)
    dll_off : message "Defaut_com_Serie"
 end_if
end_sub

' =======S/P==Fin=============
sub affichtxt(nxt,par,tpt,ltt,fsize,txt$)
 container nxt:parent nxt,par:top nxt,tpt:left nxt,ltt
 Alpha nxt+1:parent nxt+1,nxt:top nxt+1,10:left nxt+1,10
 font_bold 1:font_size 1,fsize
 width nxt+1,text_width(txt$,1)
 width nxt,width(nxt+1)+20
 font_bold nxt+1:font_size nxt+1,fsize
 caption nxt+1,txt$
 height nxt,height(nxt+1)+20
end_sub

' ====================
sub button_container(nbc,par,tpc,ltc,txt$)
 container nbc:parent nbc,par:top nbc,tpc:left nbc, ltc
 caption nbc ,txt$
 button nbc+1:parent nbc+1,nbc:top nbc+1,30:left nbc+1,10
 width nbc+1,40:hint nbc+1,nbc+1
 width nbc,width(nbc+1)+20
 height nbc,height(nbc+1)+50
end_sub
' ====================
sub voyant_automate(ntp,par,ttp,ltp,txt$,etat)
 container ntp:parent ntp,par:top ntp,ttp:left ntp,ltp
 width ntp,80-20: height ntp,133-50
 font_size ntp,14:caption ntp,txt$
 alpha ntp+1:parent ntp+1,ntp:top ntp+1,48-20:left ntp+1,7
 width ntp+1,64-20: height ntp+1,44:color ntp+1,0,0,0
 progress_bar  ntp+2:parent ntp+2,ntp:top ntp+2,52-20:left ntp+2,11
 width ntp+2,56-20: height ntp+2,36:min ntp+2,0:max ntp+2,1
 hint ntp+2,ntp+2
 if etat=0
    position ntp+2,0
 else
    position ntp+2,1
 end_if

end_sub
' =====réception========
sp_reception:
 if com_ok=1
    a%=DLL_CALL1("ComGetDataIn",adr(dat%))
    pause 5
     ' *****************************************
     WHILE a%>0
         if dat%> 47 and a% <58
            donner$=donner$+chr$(dat%)
         end_if
         if chr$(dat%)="%"
             poubele$=chr$(dat%)
             donner$=trim$(donner$)
             if numeric(donner$)=1 then tension=val(donner$)
             gosub calcul_resistance
             donner$="" :dat%=0 :tension=0
             exit_while
         end_if
        a%=DLL_CALL1("ComGetDataIn",adr(dat%))
        pause 5
     END_WHILE
     ' *****************************************
end_if
return
' ====================
sp_Mesure:
if com_ok =1
  a1%= dll_call1("ComSetDataOut",116)
  ' 116=t pour émettre 1 fois
  pause 4
  gosub sp_reception
end_if
return
' ====================
sp_stop_com:
if com_ok=1
 pause 10
  aa%= dll_call1("ComUsePort",0)
  dll_off
 com_ok=0:a%=0:aa%=0:active 51:show 40
 position 32,0:caption 21,"0.00"
 end_if
return
' ====================
calcul_resistance:
 vr1=tension*(5/1023)
 ir=vr1/1009
 if ir<>0
 rt=5/ir
 rx%=rt-1009:' <= valeur à mesurer de R1
caption 21,str$(rx%)
else
message "Défaut mesure"
caption 21,""
end_if
return
' ====================
' ====================
' ====================
' liste des objets systeme
'
'   FORM          0                       W 1000  H 480
'   ALPHA         1  parent   0  type  6  W    8  H  32
'   CONTAINER    10  parent   0  type 23  W  154  H  44
'   ALPHA        11  parent  10  type  6  W  135  H  24
'   CONTAINER    20  parent   0  type 23  W  118  H  52
'   ALPHA        21  parent  20  type  6  W   99  H  32
'   CONTAINER    30  parent   0  type 23  W   60  H  83
'   ALPHA        31  parent  30  type  6  W   44  H  44
'   PROGRESS_BAR 32  parent  30  type 20
'   CONTAINER    40  parent   0  type 23  W   60  H  75
'   BUTTON       41  parent  40  type  2  W   40  H  25
'   CONTAINER    50  parent   0  type 23  W   60  H  75
'   BUTTON       51  parent  50  type  2  W   40  H  25
'   CONTAINER    60  parent   0  type 23  W   60  H  75
'   BUTTON       61  parent  60  type  2  W   40  H  25
'   CONTAINER    70  parent   0  type 23  W  162  H 165
'   ALPHA        71  parent  70  type  6  W  119  H  40
'   CONTAINER    80  parent   0  type 23  W   60  H  75
'   BUTTON       81  parent  80  type  2  W   40  H  25
'   CONTAINER    90  parent   0  type 23  W  233  H  44
'   ALPHA        91  parent  90  type  6  W  214  H  24
'   CONTAINER   120  parent   0  type 23  W   75  H  52
'   ALPHA       121  parent 120  type  6  W   53  H  34

' ====================


code



// resistance_20140514
//........................
int mesure=0;
//.............................
void setup() {
Serial.begin(115200); 
}
//============================
void loop(){
   if (Serial.available()!=0){
  module_reception();}
}
//============================
void module_reception(){

  while (Serial.available()) {
    char readChar = (char)Serial.read();
    if (readChar == 't'){
    emission();}
  } 
}  
//..................................
void emission(){
  mesure=analogRead(0);
  Serial.print(mesure,DEC);
   Serial.println("%");
  delay(10);
}
//........................

loulou08 forum Panoramic



Aucun commentaire:

Enregistrer un commentaire