Advertisement
Guest User

ledctrl_pc

a guest
Jul 30th, 2010
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. //      ledmvl.c
  2. //      
  3. //      Copyright 2010 Serch <daemonfreedom.blogspot.com>
  4. //      
  5. //      This program is free software; you can redistribute it and/or modify
  6. //      it under the terms of the GNU General Public License as published by
  7. //      the Free Software Foundation; either version 2 of the License, or
  8. //      (at your option) any later version.
  9. //      
  10. //      This program is distributed in the hope that it will be useful,
  11. //      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //      GNU General Public License for more details.
  14. //      
  15. //      You should have received a copy of the GNU General Public License
  16. //      along with this program; if not, write to the Free Software
  17. //      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. //      MA 02110-1301, USA.
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. char ruta[13];
  24.  
  25. FILE *fp;
  26.  
  27. int pedirNum();
  28. void abrir();
  29.  
  30. int main(void)
  31. {
  32.     int var;
  33.     strncpy(ruta, "/dev/ttyUSB0", 13);
  34.  
  35.     if ((fp=fopen(ruta, "a"))==NULL)
  36.     {
  37.         fprintf(stdout, "No se puede abrir el archivo\n");
  38.         return 0;
  39.     }
  40.  
  41.     fcloseall();
  42.  
  43.     do
  44.     {
  45.         fprintf(stdout, "Introduce valor (0 para salir)\n");
  46.         var =pedirNum();
  47.         if (var==0)
  48.         {
  49.             abrir(); putc(0, fp); fclose(fp);
  50.             break;
  51.         }
  52.  
  53.         else
  54.         {
  55.             switch(var)
  56.             {
  57.                 case 1: abrir(); fputc(1, fp); fclose(fp); break;
  58.                 case 2: abrir(); fputc(2, fp); fclose(fp); break;
  59.                 case 3: abrir(); fputc(3, fp); fclose(fp); break;
  60.                 case 4: abrir(); fputc(4, fp); fclose(fp); break;
  61.             }
  62.         }
  63.     } while (1);
  64.  
  65.     return 0;
  66. }
  67.  
  68. int pedirNum()
  69. {
  70.     int valor;
  71.     do
  72.     {
  73.         scanf("%d", &valor);
  74.     } while (valor<0 || valor>4);
  75.     return valor;
  76. }
  77.  
  78. void abrir()
  79. {
  80.     if ((fp=fopen(ruta, "w"))==NULL)
  81.     {
  82.         fprintf(stdout, "Imposible abrir el archivo\n");
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement