Lesson 4. Analog Inputs

 

Overview

In this lesson, you will rewrite Blink code. However, your delay function change according to your ESPcopter Battery value.

 

Code

// These constants won’t change. They’re used to give names to the pins used:
const int analogInPin = 0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 2; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(6*sensorValue, 3300, 4200, 0, 100);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the Serial Monitor:
Serial.print(“sensor = “);
Serial.print(sensorValue);
Serial.print(“\t output = “);
Serial.println(outputValue);

// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);
}


Lesson 3. The Serial Monitor Hello World

 

Hello World

The easiest way to start working with ESPcopter with Arduino begins here. You’ll learn how to output print statements. The ESPcopte can use a Serial Monitor for displaying information such as print statements, sensor data, and the like. This is a very powerful tool for debugging long codes. Now for your first code!

Code

 

/*

Blink ESPcopter

By Metehan Emlik

*/

void setup() {

Serial.begin(9600);

} void loop() {

Serial.println(“Hello World!”);

delay(1000);

}


Lesson 2. RGB LEDs

Overview

 

In this lesson, you will learn how to use a RGB (Red Green Blue) LED with an Espcopter.

At first glance, RGB (Red, Green, Blue) LEDs look just like regular LEDs, however, inside the usual LED package, there are actually three LEDs, one red, one green and yes, one blue. By controlling the brightness of each of the individual LEDs you can mix pretty much any color you want.

You will use the analogWrite function of Arduino to control the color of the LED.

Code

int bluePin = 16; // unreverse
int redPin = 2; //reverse
int greenPin = 0; //revers

int wait = 500;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(bluePin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(bluePin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(wait); // wait for a second
digitalWrite(bluePin, LOW); // turn the LED off by making the voltage LOW
digitalWrite(redPin, LOW); // turn the LED on (HIGH is the voltage level)
delay(wait); // wait for a second
digitalWrite(redPin, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(greenPin, LOW); // turn the LED on (HIGH is the voltage level)
delay(wait); // wait for a second
digitalWrite(greenPin, HIGH); // turn the LED off by making the voltage LOW
}


Lesson 1. Blink

/*

Blink ESPcopter

By Metehan Emlik

*/

int bluePin = 16; // Düz
int redPin = 2; //Ters
int greenPin = 0; //Ters

int bekleme = 500;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(bluePin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(bluePin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(bekleme); // wait for a second
digitalWrite(bluePin, LOW); // turn the LED off by making the voltage LOW

delay(bekleme); // wait for a second
}