Init commit with many years of arduino sketches and projects. I dont know if the esp8266 includes much, but there are also libraries. I hope they dont have crazy automatic versioning through the Arduino IDE.

This commit is contained in:
2019-05-30 23:41:53 +02:00
parent 2d047634f2
commit 6c84b31f2c
1480 changed files with 198581 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
/*
* created by Rui Santos, http://randomnerdtutorials.wordpress.com
* Control DC motor with Smartphone via bluetooth
* 2013
*/
int motorPin1 = 3; // pin 2 on L293D IC
int motorPin2 = 4; // pin 7 on L293D IC
int enablePin = 5; // pin 1 on L293D IC
int state;
int flag=0; //makes sure that the serial only prints once the state
void setup() {
// sets the pins as outputs:
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
// sets enablePin high so that motor can turn on:
digitalWrite(enablePin, HIGH);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
//if some date is sent, reads it and saves in state
if(Serial.available() > 0){
state = Serial.read();
flag=0;
}
// if the state is '0' the DC motor will turn off
if (state == '0') {
digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
if(flag == 0){
Serial.println("Motor: off");
flag=1;
}
}
// if the state is '1' the motor will turn right
else if (state == '1') {
digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
digitalWrite(motorPin2, HIGH); // set pin 7 on L293D high
if(flag == 0){
Serial.println("Motor: right");
flag=1;
}
}
// if the state is '2' the motor will turn left
else if (state == '2') {
digitalWrite(motorPin1, HIGH); // set pin 2 on L293D high
digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
if(flag == 0){
Serial.println("Motor: left");
flag=1;
}
}
}

View File

@@ -0,0 +1,37 @@
int latchPin = 12;
int clockPin = 11;
int dataPin = 13;
byte leds = 0;
int currentLED = 0;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
leds = 0;
}
void loop()
{
leds = 0;
if (currentLED == 7)
{
currentLED = 0;
}
else
{
currentLED++;
}
bitSet(leds, currentLED);
digitalWrite(latchPin, LOW);
delay(250);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
delay(250);
}

View File

@@ -0,0 +1,114 @@
int temperaturePin = 0;
const int buttonPin = 0;
int secondDisplayState = HIGH;
const boolean ON = HIGH;
const boolean OFF = LOW;
int buttonState, Avrund;
int firstDisplay[] = {10, 9, 8, 7, 6, 5, 4};
int data = 11;
int latch = 12;
int clock = 13;
byte firstNumber[10][7] = {
{ON, ON, ON, OFF, ON, ON, ON}, // 0
{ON, OFF, OFF, OFF, OFF, OFF, ON}, // 1
{OFF, ON, ON, ON, OFF, ON, ON}, // 2
{ON, ON, OFF, ON, OFF, ON, ON}, // 3
{ON, OFF, OFF, ON, ON, OFF, ON}, // 4
{ON, ON, OFF, ON, ON, ON, OFF}, // 5
{ON, ON, ON, ON, ON, ON, OFF}, // 6
{ON, OFF, OFF, OFF, OFF, ON, ON}, // 7
{ON, ON, ON, ON, ON, ON, ON}, // 8
{ON, ON, OFF, ON, ON, ON, ON}}; // 9
byte secondNumber[5][7] = {
{OFF, ON, ON, ON, ON, ON, ON}, // 0
{OFF, OFF, OFF, ON, OFF, OFF, ON}, // 1
{ON, ON, ON, OFF, OFF, ON, ON}, // 2
{ON, ON, OFF, ON, OFF, ON, ON}, // 3
{ON, OFF, OFF, ON, ON, OFF, ON}}; // 4
void setup()
{
pinMode(buttonPin, INPUT);
Serial.begin(9600);
for (int i = 0; i < 7; i++)
{
pinMode(firstDisplay[i], OUTPUT);
}
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
}
void loop()
{
Avrund = 0;
buttonState = digitalRead(buttonPin);
if (buttonState == LOW)
{
float temperature = getVoltage(temperaturePin);
temperature = (temperature - .5) * 100;
Serial.print(temperature);
Serial.println(" Celsius");
temperature = temperature * 10;
int intConvertedTemp = (int) temperature;
String stringConvertedTemp = (String) intConvertedTemp;
for (int i = 0; i < 10; i++)
{
if (stringConvertedTemp.substring(0,1) == (String) i)
{
for (int j = 0; j < 7; j++)
{
changeThe7Segments(j, secondNumber[i][j]);
}
}
if (stringConvertedTemp.substring(2,3) > "5")
{
Avrund = 1;
}
if (stringConvertedTemp.substring(1,2) == (String) i)
{
for (int j = 0; j < 7; j++)
{
digitalWrite(firstDisplay[j], firstNumber[i + Avrund][j]);
}
}
}
delay(1250);
for (int i = 0; i < 7; i++)
{
digitalWrite(firstDisplay[i], OFF);
changeThe7Segments(i, OFF);
}
}
}
float getVoltage(int pin)
{
return (analogRead(pin) * .004882814);
}
void updateSecondDisplay(int value)
{
digitalWrite(latch, LOW);
shiftOut(data, clock, MSBFIRST, value);
digitalWrite(latch, HIGH);
}
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
void changeThe7Segments(int led, int state)
{
secondDisplayState = secondDisplayState & masks[led];
if(state == ON)
{
secondDisplayState = secondDisplayState | bits[led];
}
updateSecondDisplay(secondDisplayState);
}

View File

@@ -0,0 +1,46 @@
/* ---------------------------------------------------------
* | Arduino Experimentation Kit Example Code |
* | CIRC-10 .: Temperature :. (TMP36 Temperature Sensor) |
* ---------------------------------------------------------
*
* A simple program to output the current temperature to the IDE's debug window
*
* For more details on this circuit: http://tinyurl.com/c89tvd
*/
//TMP36 Pin Variables
int temperaturePin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade
//(500 mV offset) to make negative temperatures an option
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the copmuter
//to view the result open the serial monitor
//last button beneath the file bar (looks like a box with an antenae)
}
void loop() // run over and over again
{
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
temperature = (temperature - .5) * 100; //converting from 10 mv per degree with 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperature); //printing the result
Serial.print(" Celsius ");
Serial.print(getVoltage(temperaturePin));
Serial.println(" Volt");
delay(1000); //waiting a second
}
/*
* getVoltage() - returns the voltage on the analog input defined by
* pin
*/
float getVoltage(int pin){
return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}