Commit b6aaa60b by Risto Heinsar

Added wk3 demo codes

parent 9a4348a5
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const uint16_t tickDelay = 1000;
uint32_t tickCount = 0;
void setup() {
// Initsialiseerime LCD
lcd.init();
// Lülitame LCD taustavalguse sisse
lcd.backlight();
// Kirjutame teksti LCDle, vaikimisi esimese rea algusse kui asukohta ei täpsusta
lcd.print("Korduste arv:");
// Kirjtuame teise rea positsioonidele 15 ja 16 naerunäo
lcd.setCursor(14, 1);
lcd.print(":)");
}
void loop() {
// Kirjutame teise rea algusse korduste arv
lcd.setCursor(0, 1);
lcd.print(tickCount);
lcd.print(" korda");
tickCount++;
delay(tickDelay);
}
/* Fototakisti viigu number */
#define LDR_PIN A0
/* Arduino ADC on 10-bitine - st 2^10 = 1024 */
#define ADC_RESOLUTION 1024
/* Kasuta enda Arduino võrdluspinget */
#define REF_VOLTAGE 9.00
const int tickDelay = 500;
void setup()
{
Serial.begin(9600);
pinMode(LDR_PIN, INPUT);
}
void loop()
{
int ldrReading = analogRead(LDR_PIN);
float ldrVoltage = (ldrReading / (float)ADC_RESOLUTION) * REF_VOLTAGE;
Serial.print("Valgustakisti väärtus: ");
Serial.print(ldrReading);
Serial.print("; Mõõdetud pinge: ");
Serial.println(ldrVoltage);
delay(tickDelay);
}
\ No newline at end of file
#define TICK_LIMIT 6
uint16_t tickDelay = 166;
uint8_t tickCount = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
/* Ülesannet lahendatakse 2 korda sekundis */
if (tickCount % 3 == 0)
{
Serial.print(millis() / (float)1000);
Serial.println(" Olen Boe-Bot");
}
/* Ülesannet lahendatakse 3 korda sekundis */
if (tickCount % 2 == 0)
{
Serial.print(millis() / (float)1000);
Serial.println(" Beep-Boop");
}
tickCount++;
/* Väldime loenduril tekkivat täisarvu ületäitumist! */
if (tickCount == TICK_LIMIT)
{
tickCount = 0;
}
delay(tickDelay);
}
\ No newline at end of file
#define THERMISTOR_PIN A0
/* Arduino ADC on 10-bitine - st 2^10 = 1024 */
#define ADC_RESOLUTION 1024
/* Kasuta enda Arduino võrdluspinget */
#define REF_VOLTAGE 9.00
const uint16_t tickDelay = 500;
void setup()
{
Serial.begin(9600);
pinMode(THERMISTOR_PIN, INPUT);
}
void loop()
{
uint16_t tempSensor = analogRead(THERMISTOR_PIN);
float tempInC = ((tempSensor / (float)ADC_RESOLUTION) * REF_VOLTAGE - 0.5) * 100;
Serial.print("Temperatuur: ");
Serial.print(tempInC);
Serial.println("°C");
delay(tickDelay);
}
\ No newline at end of file
#define MSEC_IN_SEC 1000
const int tickDelay = 250;
void setup()
{
Serial.begin(9600);
}
void loop()
{
uint32_t timeInMs = millis();
uint8_t timeSecPassed = timeInMs / MSEC_IN_SEC;
uint16_t timeMsPassed = timeInMs % MSEC_IN_SEC;
Serial.print("Aega möödunud: ");
Serial.print(timeSecPassed);
Serial.print("s ");
Serial.print(timeMsPassed);
Serial.println("ms");
delay(tickDelay);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment