Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

74 rader
1.9 KiB

  1. /*
  2. * voltmeter.c:
  3. * Demonstrate use of the Gertboard A to D converter to make
  4. * a simple voltmeter.
  5. *
  6. * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
  7. ***********************************************************************
  8. * This file is part of wiringPi:
  9. * https://projects.drogon.net/raspberry-pi/wiringpi/
  10. *
  11. * wiringPi is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * wiringPi is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  23. ***********************************************************************
  24. */
  25. #include <stdio.h>
  26. #include <wiringPi.h>
  27. #include <gertboard.h>
  28. int main ()
  29. {
  30. int x1, x2 ;
  31. double v1, v2 ;
  32. printf ("\n") ;
  33. printf ("Gertboard demo: Simple Voltmeters\n") ;
  34. printf ("=================================\n") ;
  35. // Always initialise wiringPi. Use wiringPiSys() if you don't need
  36. // (or want) to run as root
  37. wiringPiSetupSys () ;
  38. // Initialise the Gertboard analog hardware at pin 100
  39. gertboardAnalogSetup (100) ;
  40. printf ("\n") ;
  41. printf ("| Channel 0 | Channel 1 |\n") ;
  42. for (;;)
  43. {
  44. // Read the 2 channels:
  45. x1 = analogRead (100) ;
  46. x2 = analogRead (101) ;
  47. // Convert to a voltage:
  48. v1 = (double)x1 / 1023.0 * 3.3 ;
  49. v2 = (double)x2 / 1023.0 * 3.3 ;
  50. // Print
  51. printf ("| %6.3f | %6.3f |\r", v1, v2) ;
  52. fflush (stdout) ;
  53. }
  54. return 0 ;
  55. }