mirror of
				https://github.com/digistump/DigistumpArduino.git
				synced 2025-11-03 21:14:46 -08:00 
			
		
		
		
	Initial import of support files for all Digistump boards - Digispark, Pro, DigiX - including libraries, examples, tools, and other support files for the Arduino IDE
This commit is contained in:
		@@ -0,0 +1,42 @@
 | 
			
		||||
#include <DigiUSB.h>
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  DigiUSB.begin();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void get_input() {
 | 
			
		||||
  // when there are no characters to read
 | 
			
		||||
  while (1==1) {
 | 
			
		||||
    if(DigiUSB.available()){
 | 
			
		||||
      //something to read
 | 
			
		||||
      DigiUSB.read();
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    // refresh the usb port
 | 
			
		||||
    DigiUSB.refresh();
 | 
			
		||||
    delay(10);
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  DigiUSB.refresh();
 | 
			
		||||
  //print output
 | 
			
		||||
  float value = analogRead(1); //This is Pin3
 | 
			
		||||
  if(value>1020)
 | 
			
		||||
    value = 255;
 | 
			
		||||
  else if(value<2)
 | 
			
		||||
    value = 0;
 | 
			
		||||
  else
 | 
			
		||||
    value = value/4;
 | 
			
		||||
   //send value
 | 
			
		||||
  
 | 
			
		||||
  value = round(byte(value));
 | 
			
		||||
  DigiUSB.write(value);
 | 
			
		||||
  
 | 
			
		||||
  //wait for response
 | 
			
		||||
  get_input();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user