augusto0112

lab10

Oct 26th, 2016
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1. /*
  2. ********** Arduino **********
  3.  * Laboratorio 10: Matriz LED 8x8 a través de IC MAX7219 dependiendo de Potenciómetro.
  4.  * Autor: Cristian Augusto Restrepo
  5.  * Descripción:
  6.  *   Controlar desde el Arduino, una matriz LED 8x8 a través de IC MAX7219,
  7.  *   para mostrar un número del 0 al 9, dependiendo de la posición del Potenciómetro.
  8. */
  9. #include "LedControlMS.h"
  10. //Antigua librería #include "LedControl.h"
  11. //Segmentos que se usan, datos seriales para estabecer cuando aparece que número
  12. //102.3 = 1, 204.6 = 2, 306.9 = 3, 409.9 = 4, 511.5 = 5,
  13. //613.8 = 6, 716.1 = 7, 818.4 = 8, 920.7 = 9, 1023 = 10
  14. #define NumMatrix 1
  15. //#define POT1 A0;
  16. int POT1 = A0;
  17. int DataPin = 9;       //pin 9 conectado a DataIn
  18. int ClockPin = 10;     //pin 10 conectado a CLK
  19. int LatchPIN = 8;      //pin 8 conectado a LOAD/CS
  20.  
  21. LedControl lc=LedControl(DataPin,ClockPin,LatchPIN,NumMatrix);
  22.  
  23. void setup() {
  24.   // initialize serial communication at 9600 bits per second:
  25.   // // //Serial.begin(9600);
  26.  
  27.   for (int i=0; i< NumMatrix ; i++)
  28.    {
  29.        lc.shutdown(i,false);  // Activar la matriz
  30.        lc.setIntensity(i,1);  // Poner el brillo a un valor intermedio
  31.        lc.clearDisplay(i);    // Y borrar todo
  32.    }
  33. }
  34.  
  35. // the loop routine runs over and over again forever:
  36. void loop() {
  37.   // read the input on analog pin 0:
  38.   int sensorValue = analogRead(A0);
  39.   // print out the value you read:
  40.   // // //Serial.println(sensorValue);
  41.   //delay(1);        // delay in between reads for stability
  42. if (sensorValue >= 0 && sensorValue <= 102.3){
  43.   lc.writeString(0,"0");
  44. }
  45. if (sensorValue >= 102.40 && sensorValue <= 204.60){
  46.   lc.writeString(0,"1");
  47. }
  48. if (sensorValue >= 204.61 && sensorValue <= 306.90){
  49.   lc.writeString(0,"2");
  50. }
  51. if (sensorValue >= 306.91 && sensorValue <= 409.90){
  52.   lc.writeString(0,"3");
  53. }
  54. if (sensorValue >= 409.91 && sensorValue <= 511.50){
  55.   lc.writeString(0,"4");
  56. }
  57. if (sensorValue >= 511.51 && sensorValue <= 613.80){
  58.   lc.writeString(0,"5");
  59. }
  60. if (sensorValue >= 613.81 && sensorValue <= 716.10){
  61.   lc.writeString(0,"6");
  62. }
  63. if (sensorValue >= 716.11 && sensorValue <= 818.40){
  64.   lc.writeString(0,"7");
  65. }
  66. if (sensorValue >= 818.41 && sensorValue <= 920.70){
  67.   lc.writeString(0,"8");
  68. }
  69. if (sensorValue >= 920.71){
  70.   lc.writeString(0,"9");
  71. }
  72.  
  73.  
  74. //delay(0);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment