Advertisement
Guest User

CNA - 8

a guest
Feb 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.37 KB | None | 0 0
  1. #include "mbed.h"
  2. AnalogOut Vs(p18);
  3. AnalogIn R47(p15);
  4. float toto,volt,tutu;
  5. int freq;
  6. void init();
  7. void frequence();
  8. void elaboration();
  9.  
  10. int main()
  11. {
  12.   init ();
  13.     frequence();
  14.    
  15.     while(1)
  16.     {
  17.     elaboration();
  18.     }
  19. }
  20.  
  21. void init()
  22. {
  23.     toto=3.3*R47;
  24.     volt=tutu/3.3;
  25. }
  26.  
  27. void frequence()
  28. {
  29.     if(toto<1)
  30.     {
  31.         freq=500;
  32.     }
  33.     if(toto<1.05&&toto>1)
  34.     {
  35.         freq=487;
  36.     }
  37.     if(toto<1.10&&toto>1.05)
  38.     {
  39.         freq=474;
  40.     }
  41.     if(toto<1.15&&toto>1.10)
  42.     {
  43.         freq=461;
  44.     }
  45.     if(toto<1.20&&toto>1.15)
  46.     {
  47.         freq=448;
  48.     }
  49.     if(toto<1.25&&toto>1.20)
  50.     {
  51.         freq=435;
  52.     }
  53.     if(toto<1.30&&toto>1.25)
  54.     {
  55.         freq=422;
  56.     }
  57.     if(toto<1.35&&toto>1.30)
  58.     {
  59.         freq=409;
  60.     }
  61.     if(toto<1.40&&toto>1.35)
  62.     {
  63.         freq=396;
  64.     }
  65.     if(toto<1.45&&toto>1.40)
  66.     {
  67.         freq=383;
  68.     }
  69.     if(toto<1.50&&toto>1.45)
  70.     {
  71.         freq=370;
  72.     }
  73.     if(toto<1.55&&toto>1.50)
  74.     {
  75.         freq=357;
  76.     }
  77.     if(toto<1.60&&toto>1.55)
  78.     {
  79.         freq=344;
  80.     }
  81.     if(toto<1.65&&toto>1.60)
  82.     {
  83.         freq=331;
  84.     }
  85.     if(toto<1.70&&toto>1.65)
  86.     {
  87.         freq=318;
  88.     }
  89.     if(toto<1.75&&toto>1.70)
  90.     {
  91.         freq=305;
  92.     }
  93.     if(toto<1.80&&toto>1.75)
  94.     {
  95.         freq=292;
  96.     }
  97.     if(toto<1.85&&toto>1.80)
  98.     {
  99.         freq=279;
  100.     }
  101.     if(toto<1.90&&toto>1.85)
  102.     {
  103.         freq=266;
  104.     }
  105.     if(toto<1.95&&toto>1.90)
  106.     {
  107.         freq=253;
  108.     }
  109.     if(toto<2&&toto>1.95)
  110.     {
  111.         freq=240;
  112.     }
  113.     if(toto<2.05&&toto>2.00)
  114.     {
  115.         freq=227;
  116.     }
  117.     if(toto<2.10&&toto>2.05)
  118.     {
  119.         freq=214;
  120.     }
  121.     if(toto<2.15&&toto>2.10)
  122.     {
  123.         freq=201;
  124.     }
  125.     if(toto<2.20&&toto>2.15)
  126.     {
  127.         freq=188;
  128.     }
  129.     if(toto<2.25&&toto>2.20)
  130.     {
  131.         freq=175;
  132.     }
  133.     if(toto<2.30&&toto>2.25)
  134.     {
  135.         freq=162;
  136.     }
  137.     if(toto<2.35&&toto>2.30)
  138.     {
  139.         freq=149;
  140.     }
  141.     if(toto<2.40&&toto>2.35)
  142.     {
  143.         freq=136;
  144.     }
  145.     if(toto<2.45&&toto>2.40)
  146.     {
  147.         freq=123;
  148.     }
  149.     if(toto<2.50&&toto>2.45)
  150.     {
  151.         freq=110;
  152.     }
  153.     if(toto<2.55&&toto>2.50)
  154.     {
  155.         freq=97;
  156.     }
  157.     if(toto<2.60&&toto>2.55)
  158.     {
  159.         freq=84;
  160.     }
  161.     if(toto<2.65&&toto>2.60)
  162.     {
  163.         freq=71;
  164.     }
  165.     if(toto<2.70&&toto>2.65)
  166.     {
  167.         freq=58;
  168.     }
  169.     if(toto<2.75&&toto>2.70)
  170.     {
  171.         freq=45;
  172.     }
  173.     if(toto<2.80&&toto>2.75)
  174.     {
  175.         freq=32;
  176.     }
  177.     if(toto<2.85&&toto>2.80)
  178.     {
  179.         freq=19;
  180.     }
  181.     if(toto<2.90&&toto>2.85)
  182.     {
  183.         freq=6;
  184.     }
  185.     if(toto<2.95&&toto>2.90)
  186.     {
  187.         freq=1;
  188.     }
  189. }
  190.  
  191. void elaboration()
  192. {
  193.     while(tutu<20)
  194.     {
  195.         Vs.write(volt);
  196.         wait_us(freq);
  197.         tutu=tutu+0.5;
  198.         volt=tutu/33;
  199.     }
  200.     while(tutu>10)
  201.     {
  202.         Vs.write(volt);
  203.         wait_us(freq);
  204.         tutu=tutu-0.5;
  205.         volt=tutu/33;
  206.     }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement