Advertisement
Trepur1994

Attiny 45 Würfel (Arduino)

Jul 8th, 2016
2,791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //________________Variabeln_____________________
  2. int output_array[]={2,1,0,4};
  3. int arraylaenge =4;
  4. int zahl_kombi[7][4]={
  5.                       {0,1,1,1}       //Ausgabe der Zahl 1
  6.                      ,{1,0,1,1}       //Ausgabe der Zahl 2
  7.                      ,{0,0,1,1}       //Ausgabe der Zahl 3
  8.                      ,{1,0,0,1}       //Ausgabe der Zahl 4
  9.                      ,{0,0,0,1}       //Ausgabe der Zahl 5
  10.                      ,{1,0,0,0}       //Ausgabe der Zahl 6
  11.                      ,{1,1,1,1}       //Ausgabe der Zahl 0 (Alle LED´s sind nun aus)
  12.                      };
  13. int input_Pin = 3;
  14. int array_Zahlen[100];
  15. int zahl = 0;
  16.  
  17. //_____________Initalisierung__________________
  18. void setup()
  19. {
  20. for(int i;i<arraylaenge;i++)
  21. {
  22.  pinMode(output_array[i],OUTPUT);
  23. }
  24. pinMode(input_Pin,INPUT);
  25. }
  26.  
  27. //___________Hauptschleife______________________
  28. void loop()
  29. {
  30. zufall();
  31. }
  32.  
  33. //____________Methoden____________________________
  34. void ausgabe(int mode)
  35. {
  36. for(int i;i<arraylaenge;i++)
  37. {
  38.  if(zahl_kombi[mode][i]==1)
  39.  {
  40.  digitalWrite(output_array[i],HIGH);
  41.  }
  42.  else
  43.  {
  44.  digitalWrite(output_array[i],LOW);
  45.  }
  46. }
  47. }
  48.  
  49. void zufall()
  50. {
  51.   while(digitalRead(input_Pin)==1)   // Schaut ob eine Eingabe erfolgt ist.
  52.  {
  53.    ausgabe (6);                  // Setzt die Ausgabe zurück
  54.    
  55.    for(int a; a < 6; a++)
  56.    {
  57.      ausgabe(a);
  58.      delay(1000);
  59.    }
  60.  
  61.    ausgabe(random(0,6));
  62.  }
  63. delay(100);                      // wartet 100 ms
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement