พอดีผมโหลดโค๊ดเสียงมา แล้วจะเบริ์นลง Atiny85 เบริน์ผ่าน แต่ไม่มีเสียงออก โค๊ดตามนี้คับ
โดยผมกำหนดให้เสียงออก Pin1 แต่เบิร์นแล้วไม่มีเสียง แต่ถ้าเบิร์นผ่าน Arduino แล้วเอาลำโพงไปต่อบอร์ด Arduino กลับมีเสียงเพลง แต่ใช้โค๊ดเดียวกัน เบิร์นลง Atiny85 กลับไม่มีเสียง ไม่ว่าทราปว่ามีอะไรผิดเปล่าคับ
/* toneMelody_ΑΑ
circuit: 8-ohm speaker on digital pin 8 & GND
created 18 Apr 2013 by AA --- toneMelody_ΑΑ.ino */
#include "pitches.h"
// notes in the melody:
int melody[]= {NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, NOTE_C4, NOTE_B3,
NOTE_G3,NOTE_G3, NOTE_A3,NOTE_G3, NOTE_D4, NOTE_C4,
NOTE_G3, NOTE_G3, NOTE_G4,NOTE_E4,NOTE_C4, NOTE_B3, NOTE_A3,
NOTE_F4, NOTE_F4, NOTE_E4, NOTE_C4, NOTE_D4, NOTE_C4 };
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = { 8,8,4,4,4,2,8,8,4,4,4,2,8,8,4,4,4,4,3,8,8,4,4,4,2 };
void setup()
{
}
void loop()
{
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 26; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(1, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.60;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(1);
}
}
ขาของ Attiny85 กับ Atmega328 ไม่เหมือนกัน ชื่อเรียกขาต่างกัน เอาโคดของ Atmega328 ไปใส่ Attiny85 โดยตรงไม่ได้ ลองเช็คตำแหน่งขาในโคดกับ Attiny85 อีกทีครับ
คับ ขา PIN attiny มีขา 0-4 ผมเลยลองใส่ช่อง tone() เป็น 0-4 ก็ยังไม่ได้ ลองเลือกแบบตัวอย่างใน arduino example แล้วก็ไม่ได้เหมือนกันคับ เลยไม่รู้ว่าผิดที่ตรงไหน
ทำได้แน่นอน ลองตัวอย่างนี้ครับ
https://softcircuitsfall12.wordpress.com/2012/12/04/attiny-sound-tutorial-by-shaan-minsung-maxine/
ตัวอย่างนี้ลองแล้วคับ ใช้โค๊ดของเขาเลย แต่กดแล้วไม่มีเสียง ผมเลยสงสัยว่าเกิดจากอะไร ปัญหามันคือไม่มีเสียงออก แต่ถ้าเอาคำสั่งเขา เบิร์นลง Arduino มีเสียง แต่พอเบิร์นลง Attiny ไม่มีเสียงคับ ผมเลยไม่เข้าใจ
ตามตัวอย่างลิงค์ที่ให้ไปเขียนบอกไว้ว่า
There is however one problem with this code if we want to use it with ATtiny. ATtiny does not accept the TONE function.
To make it work with the tone function visit this thread:
http://arduino.cc/forum/index.php?action=printpage;topic=61607.0
core ของ Attiny85 ไม่มีคำสั่ง tone()
For a recent project based on the ATtiny85 I wanted to play some simple tones through a piezoelectric speaker, but unfortunately the Arduino tone() function isn't supported on the ATtiny85 because it doesn't have the appropriate timers. I therefore needed to find a replacement way of generating simple tones.
อ้างอิง http://highlowtech.org/?p=1695
The following Arduino commands should be supported:
สามารถดัดแปลงโคด ใช้โคดนี้ ผมทดลองให้แล้ว
http://www.technoblogy.com/show?KVO
หรือจะหา attiny85 core ตัวใหม่ที่รองรับคำสั่ง tone มาติดตั้งก็ได้ครับตามที่เจ้าของบทความแนะนำก็ได้ครับ
To make it work with the tone function visit this thread:
http://arduino.cc/forum/index.php?action=printpage;topic=61607.0