ความรู้แน่น ฟรีสำหรับชุมชน ArduinoAll ที่นี่เท่านั้น

ฟรีและดีที่สุด คอร์สอบรม Arduino + NodeMCU
ทำเพื่อแบ่งปัน ห้ามนำไปจำหน่าย หรือเก็บเงินค่าเรียน
  !!!


  


AllNewStep รับประกันคุณภาพทุกชิ้น วันจันทร์-ศุกร์แจ้งชำระสินค้าก่อน 14.00 จัดส่งทันทีวันนี้ค่ะ

กรุงเทพ /ภาคกลาง ได้พรุ่งนี้


*** สินค้าทุกชิ้น ถ้าสามารถทำรายการสั่งซื้อได้ แสดงว่ามีครบทุกรายการค่ะ *** 

พิมพ์ค้นหาบทความ หัวข้อกระทู้ และสินค้าในเว็บ AllNewStep ได้ที่นี่
QUOTE 

สอบถามหน่อยครับ

Zero

ต้องการทำสวิตเมื่อกดสวิตค้างไว้ledจะยังไม่ติดแต่ถ้าปล่อยสวิตแล้วledถึงจะทำงาน

    

QUOTE 
ความคิดเห็นที่ #1
ธีรพงษ์
ดู example ชื่อ Debounce ครับ อยู่ที่ File -> Examples -> 02.Digital -> Debounce ดัดแปลงเอา ลองเพิ่ม debounce delay time
QUOTE 
ความคิดเห็นที่ #2
เจ้าของร้าน

ขอบคุณที่ช่วยแชร์ครับ

ขอเสริมอีกตัวอย่าง ตามนี้ครับ https://www.arduino.cc/en/Tutorial/InputPullupSerial

QUOTE 
ความคิดเห็นที่ #3
Zero
ขอบคุณครับ
QUOTE 
ความคิดเห็นที่ #4
เจ้าของร้าน

ไม่ยาก ลองฝึกเขียนโปรแกรมเล่นดูนะครับ

QUOTE 
ความคิดเห็นที่ #5
Frank
const int analogPin = A0; // the pin that the potentiometer is attached to const int ledCount = 10; // the number of LEDs in the bar graph int ledPins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; // an array of pin numbers to which LEDs are attached void setup() { // loop over the pin array and set them all to output: for (int thisLed = 0; thisLed < ledCount; thisLed++) { pinMode(ledPins[thisLed], OUTPUT); } } void loop() { // read the potentiometer: int sensorReading = analogRead(analogPin); // map the result to a range from 0 to the number of LEDs: int ledLevel = map(sensorReading, 0, 1023, 0, ledCount); // loop over the LED array: for (int thisLed = 0; thisLed < ledCount; thisLed++) { // if the array element's index is less than ledLevel, // turn the pin for this element on: if (thisLed < ledLevel) { digitalWrite(ledPins[thisLed], HIGH); } // turn off all pins higher than the ledLevel: else { digitalWrite(ledPins[thisLed], LOW); } } } // ต้องเพิ่มเสียง เมื่อหมุนVrแล้วไฟดวงสุดท้ายติดมีเสียง คล้ายกับการแจ้งเตือนอะครับ
QUOTE 
ความคิดเห็นที่ #6
ธีรพงษ์

ข้างบนเป็นปุ่มกด ข้างล่างเป็นหมุนซะแล้ว

จาก sketch ที่ให้มา เหมือนหมุนแล้ว LED bar สว่างเป็นแถบตาม volume ที่หมุน ถ้าไฟดวงสุดท้ายติด แสดงว่า ledLevel=10 ก็ที่นอก for loop ท้าย sketch เพิ่ม

if (ledLevel == ledCount) {

digitalWrite(BuzzerPins, HIGH);

delay (500);

}

digitalWrite(BuzzerPins, LOW);

แต่ code นี้จะดังค้างแค่ 500ms ถ้านานกว่านี้ ไม่แนะนำให้ใช้ delay เพราะจะไป block code อื่น เช่นถ้าใส่ delay เป็น 5000 (5 วิ) ช่วง 5 วิ นี่ หมุนแล้ว LED ไม่วิ่งเลย เพราะโค้ดค้างอยู่ที่บรรทัด delay ต้องเปลี่ยน delay เป็นโค้ดจับเวลาแบบ non-blocking แทน ลองเล่นดูครับ ไม่ยาก

QUOTE 
ความคิดเห็นที่ #7
เจ้าของร้าน

ขอบคุณที่ช่วยแชร์ครับ

แนะนำเพิ่มเติม ไลบารี หน่วงเวลาแบบไม่ต้อง delay 

http://blog.protoneer.co.nz/arduino-task-scheduler/

 

แสดงความคิดเห็นที่ 1-7 จากทั้งหมด 7 ความคิดเห็น
ขาย ARDUINO
คุณภาพ อันดับ 1

ได้รับรางวัลร้านยอดเยี่ยม
ตั้งแต่ปี 2558
ขาย Arduino
วีดีโอสอน Arduino

สอน esp8266

สอน Arduino IoT
สอน Arduino แบบเร็ว

สอน NodeMCU

อุปกรณ์ Arduino

MEMBER ZONE

พูดคุย-สอบถาม