charlieplexing
This commit is contained in:
		
							parent
							
								
									3c2eba78f0
								
							
						
					
					
						commit
						d97a5aa793
					
				
					 4 changed files with 72 additions and 0 deletions
				
			
		
							
								
								
									
										32
									
								
								projekte/charlieplexing/sketch_may18a/sketch_may18a.pde
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								projekte/charlieplexing/sketch_may18a/sketch_may18a.pde
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,32 @@
 | 
			
		|||
const int pins[] = {2, 3, 4};
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  for(int p=0; p<=2; p++) {
 | 
			
		||||
    pinMode(pins[p], INPUT); 
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const int charlieplexed[6][3] =
 | 
			
		||||
{
 | 
			
		||||
  { 1,0,-1},
 | 
			
		||||
  { 0,1,-1},
 | 
			
		||||
  {-1,1, 0},
 | 
			
		||||
  {-1,0, 1},
 | 
			
		||||
  {1,-1, 0},
 | 
			
		||||
  {0,-1, 1},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  for(int i=0; i<=5; i++) {
 | 
			
		||||
    // set pin tristate
 | 
			
		||||
    for(int p=0; p<=2; p++) {
 | 
			
		||||
      if (charlieplexed[i][p] == -1) {
 | 
			
		||||
        pinMode(pins[p], INPUT);
 | 
			
		||||
      } else {
 | 
			
		||||
        pinMode(pins[p], OUTPUT);
 | 
			
		||||
        digitalWrite(pins[p], charlieplexed[i][p]);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  delay(200);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue