The Arduino Workshop : NTUA Greek vol2

download The Arduino Workshop : NTUA Greek vol2

of 18

Embed Size (px)

Transcript of The Arduino Workshop : NTUA Greek vol2

  1. 1. The Arduino Workshop Vol 2: Back to Analog! IEEE NTUA Student Branch
  2. 2. IEEE NTUA Student Branch analogRead() : analogRead(Analog In) : 0 1023 . (1023 = 5V)
  3. 3. IEEE NTUA Student Branch
  4. 4. IEEE NTUA Student Branch +5V GND A0
  5. 5. IEEE NTUA Student Branch void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A0); Serial.println(sensorValue); delay(1); } A0. sensorValue 0 1023! 1ms .
  6. 6. IEEE NTUA Student Branch Volt : analogRead() 1023, 5.0 Volt. analogRead() , x (?) Volt. ( C): x = (5.0/1023)*
  7. 7. IEEE NTUA Student Branch void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A0); float voltage = sensorValue * (5.0/1023); Serial.println(voltage); delay(1); } , . float.
  8. 8. IEEE NTUA Student Branch map() : map(value, fromLow, fromHigh, toLow, toHigh) : value , fromLow , fromHigh toLow toHigh . , .
  9. 9. IEEE NTUA Student Branch void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A0); int newValue = map(sensorValue, 0, 1023, 0, 255); Serial.println(newValue); delay(1); } -
  10. 10. IEEE NTUA Student Branch Fade A Led: vol. 2 GND LED (pin 10)
  11. 11. IEEE NTUA Student Branch void setup() { pinMode(10, OUTPUT); } void loop() { int sensorValue = analogRead(A0); int ledValue = map(sensorValue, 0, 1023, 0, 255); analogWrite(10, ledValue); delay(1); } analogWrite LED . analogWrite 0 255, analogRead 0 1023. map(). LED ledValue.
  12. 12. IEEE NTUA Student Branch ... void newMethod(int a; float b; ...) { ... } void setup() { .. newMethod(j, b); } void loop() { .. }
  13. 13. IEEE NTUA Student Branch link A Led: vol. 2 LED , 50ms 2000ms (2s). void blink(int time) { digitalWrite(10, HIGH); delay(time); digitalWrite(10, LOW); delay(time); }
  14. 14. IEEE NTUA Student Branch link A Led: vol. 2 void setup() { pinMode(10, OUTPUT); } void loop() { int sensorValue = analogRead(A0); int timeValue = map(sensorValue, 0, 1023, 50, 2000); blink(timeValue); delay(1); } map() sensorValue 0 - 1023 50 - 2000
  15. 15. IEEE NTUA Student Branch Big Challenge (Volt) . , , . , . , LED, 2 LED : LED . LED . LED . LED 3 LED. . : 2 LED, 1 , 1 , 1 (10k)
  16. 16. IEEE NTUA Student Branch 1 int monades(float volt;) { int mon = (int) volt; return mon; } float . int dekata(float volt;) { float dec = volt - monades(volt); dec = dec * 10; int decimal = (int) dec; return decimal; }
  17. 17. IEEE NTUA Student Branch 2 void blink(int times; int pin;) { for(int i = 1; i