Skip to content

Instantly share code, notes, and snippets.

@tps2015gh
Last active April 13, 2017 18:36
Show Gist options
  • Save tps2015gh/eb262fd9f8ce5e916bd70aeb75ecef8a to your computer and use it in GitHub Desktop.
Save tps2015gh/eb262fd9f8ce5e916bd70aeb75ecef8a to your computer and use it in GitHub Desktop.
Demo Ardruino.MD

Equip

  • I use Ardruino NANO (China Version)
  • Ardruino IDE 1.8.2

Learning

  • circuits.io for simulate
  • SPA YX-360TR E-B for Probe/Test/And Learn

setup in Ardruino IDE

  • Board : Arduino NANO
  • Processor : ATmega328 <== VERY IMPORTANT !!!! / if set as ATmega168 cause CAN NOT UPLOAD PROGRAM !!!
  • Port : COM4
  • Programmer : AVR ISP
  • Run Android IDE as Administrator
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
int d9 = 9 ;
int delay1 = 200;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(d9, OUTPUT);
}
float vto255(float f_volt) {
float ratio = 51.0 ; /* convert from 5 volt to 3 volt scale 255 */
float ret = ratio * f_volt ;
if (ret > ratio* 3.0) {
ret = ratio * 3.0;
}
if(ret < 0 ) ret = 0 ;
return ret ;
}
// the loop routine runs over and over again forever:
void loop() {
int i_volt = 30 ;
float volt255 ;
float f_volt = 0.0;
digitalWrite(led, HIGH) ;
for (f_volt = 3.0 ; f_volt > 0.0 ; f_volt -= 0.01 ) {
//f_volt = (i_volt );
volt255 = vto255(f_volt);
analogWrite(d9, volt255 );
delay(delay1);
}
digitalWrite(led, LOW) ;
for (f_volt = 0.0 ; f_volt < 3.0 ; f_volt += 0.01 ) {
//f_volt = (i_volt );
volt255 = vto255(f_volt);
analogWrite(d9, volt255 );
delay(delay1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment