Advertisement
Southclaw

8 bit LED cycle thingy

Dec 1st, 2013
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.70 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. // 0-3, 1-4, 2-5, 3-6, 4-7, 5-0, 6-1, 7-2
  4.  
  5. new
  6.     gTick = 0,
  7.     gPattern[1 char]; // to make it 8 bytes wide instead of 32
  8.  
  9. main()
  10. {
  11.     gPattern{0} = 0b11110000;
  12.  
  13.     tick();
  14. }
  15.  
  16.  
  17. forward tick();
  18. public tick()
  19. {
  20.     if(gTick > 7)
  21.         gTick = 0;
  22.  
  23.     printf("%d :   %08b", gTick, gPattern{0});
  24.  
  25.     for(new i; i < 8; i++)
  26.     {
  27.         if(gPattern{0} & (1 << i))
  28.         {
  29.             // light the LED
  30.             printf("  light LED %d", i);
  31.         }
  32.         else
  33.         {
  34.             // shut off the LED
  35.             printf("  deactivate LED %d", i);
  36.         }
  37.     }
  38.  
  39.     gPattern{0} = (gPattern{0} >> 1) | (gPattern{0} << 7);
  40.  
  41.     gTick += 1;
  42.  
  43.     SetTimer("tick", 1000, false);
  44. }
  45.  
  46. public OnPlayerSpawn(playerid)
  47. {
  48.     SetPlayerPos(playerid, 0.0, 0.0, 3.0);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement