Advertisement
RuiViana

PT_Teste_Coloisor

Oct 11th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.30 KB | None | 0 0
  1.  /*
  2.                                                                 Pins 5 and 6:[/size]
  3.                                                                 Setting  Divisor Frequency
  4.                                                                 0x01  1 62500
  5.                                                                 0x02  8 7812.5
  6.                                                                 0x03  64  976.5625
  7.                                                                 0x04  256 244.140625
  8.                                                                 0x05  1024  61.03515625
  9.  
  10.                                                                 PWM frequency 9 e 10
  11.                                                                 0x01  1 31250
  12.                                                                 0x02  8 3906.25
  13.                                                                 0x03  64  488.28125
  14.                                                                 0x04  256 122.0703125
  15.                                                                 0x05  1024  30.517578125
  16.  
  17.                                                                 Pins 11 and 3:[/size]
  18.                                                                 0x01  1 31250
  19.                                                                 0x02  8 3906.25
  20.                                                                 0x03  32  976.5625
  21.                                                                 0x04  64  488.28125
  22.                                                                 0x05  128 244.140625
  23.                                                                 0x06  256 122.0703125
  24.                                                                 0x07  1024  30.517578125
  25.   */
  26.  
  27.  
  28. #define potnPinDuracao  A0                                      // Port potenciômetro duracao pulso
  29. #define potnPinInicio  A1                                       // Port potenciômetro inicio pulso
  30. #define bobina 13                                               // Port onde seráo ligadas as bobinas
  31. int duracao = 0;                                                // Valor da duracao do pulso
  32. int inicio = 250;                                               // Valor de atraso de inicio do pulso
  33. unsigned int freq;                                              // Varialvel para correcao da frequencia
  34. bool flag = 0;                                                  // Controle de inici de pulso
  35. //-------------------------------
  36. void setup()
  37. {
  38.  
  39.   pinMode(potnPinDuracao, INPUT);                               // Port entrada duraçã0
  40.   pinMode(potnPinInicio, INPUT);                                // Port entrada inicio
  41.   pinMode(bobina, OUTPUT);                                      // Port saida bobina
  42.   attachInterrupt(0, pulse, RISING);                            // Interrupt a cada pulso
  43.  
  44.   TCCR1B = TCCR1B & B11111000 | B00000101; // Set PWM frequency for D9 & D10 :
  45.   pinMode(9, OUTPUT); // sets the pin as output
  46. //  pinMode(10, OUTPUT); // sets the pin as output
  47.  
  48. //  TCCR2B = TCCR2B & B11111000 | B00000001; // Set PWM for D3 & D11
  49. //  pinMode(3, OUTPUT); // sets the pin as output
  50. //  pinMode(11, OUTPUT); // sets the pin as output
  51. }
  52. //------------------------------
  53. void pulse()
  54. {
  55.   flag = 1;                                                     // Indica passagem bola pelo sensor
  56.   Serial.println(flag);
  57. }
  58. //-------------------------------
  59. void loop()
  60. {
  61.   //  Serial.println(flag);
  62.   analogWrite(9, 128);
  63.   inicio = map(analogRead(potnPinInicio), 0, 1023, 1 , 20);       // Valor de ajuste do atraso
  64.   delay(1);                                                     // Tempo recuperacao do ADC
  65.   duracao = map(analogRead(potnPinDuracao), 0, 1023, 1 , 20);   // Valor de ajuste da duracao
  66.   if (flag == 1)                                                // Se a bola passou
  67.   {
  68.     delay(inicio);                                            // Atrasa para ligar bobina igual ajuste
  69.     digitalWrite(bobina, HIGH);                                 // Liga bobina
  70.     delay(duracao);                                              // Duração ligada igual ajuste
  71.     digitalWrite(bobina, LOW);                                  // Desliga bobina
  72.     flag = 0;                                                   // Desabilita ligar bobina
  73.   }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement