changeset 6:495dfa41484d

Second version.
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 26 Nov 2016 14:48:37 +0100
parents 0c66e108ea9a
children 8a77f39e2f26
files alternate/alternate.ino board.fzz main/Makefile main/main.c
diffstat 4 files changed, 130 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/alternate/alternate.ino	Wed Dec 02 22:00:38 2015 +0100
+++ b/alternate/alternate.ino	Sat Nov 26 14:48:37 2016 +0100
@@ -7,12 +7,12 @@
   NOTE_FS5, NOTE_GS4, NOTE_GS5,
 };
 
-const signed char INTRO_NOTES[] PROGMEM = {
+const signed char INTRO_NOTES[] = {
   9, 12, -15, -4, 9, 12, 15, 4, 6, 10, 6, 2, -4, -15, 9, 12, -15, -4, 6, 2,
   4, 6, 13, 10, 13, 4, 0
 };
 
-const signed char MELODY_NOTES[] PROGMEM = {
+const signed char MELODY_NOTES[] = {
   -15, -17, 9, 9, 0, 3, 7, 5, 3, 0, -3, -5, -7, 7, 5, 3, 5, 9, 15, 17, 9, 15, 5,
   9, 3, 5, 3, -9, -15, 17, 9, 15, 5, 9, 3, 7, 9, 7, 5, 3, 5, -7, 3, 5, 9, 15, 5,
   9, 5, 3, -5, -3, -5, -15, -17, 9, 9, 0, 3, 7, 5, 3, 0, -3, -5, -7, 7, 5, 3, 5,
@@ -25,33 +25,25 @@
   14, -3, 3, 1, 3, 14, 16, 3, 12, 9, 12, 15, -3, -5
 };
 
-#define BEEP_PIN 4
+#define BEEP_PIN 0
 #define LED_PIN 3
 #define SPEED 1500
 
-
-void toggle_eyes() {
-  static bool blink = false;
-
-  digitalWrite(LED_PIN, blink);
-  blink = !blink;
-}
-
-
 void play(const signed char *notes, const unsigned int length) {
-  for (unsigned int n = 0; n < length; n++) {
-    signed char f = pgm_read_byte_near(notes + n);
+  for (int n = 0; n < length; ++n) {
+//    signed char f = pgm_read_byte_near(notes + n);
+    signed char f = notes[n];
     int d;
-    if (f < 0) {
-      d = SPEED / 8;
-      f = -f;
+    if (f & 0x80) {
+      d = SPEED >> 3;
+      f = f & 0x7f;
     } else {
-      d = SPEED / 16;
+      d = SPEED >> 4;
     }
     tone(BEEP_PIN, FREQ[f], d);
-    delay(1.3 * d);
+    delay(d + 300);
     noTone(BEEP_PIN);
-    toggle_eyes();
+    PORTB ^= 0x08;
   }
 }
 
Binary file board.fzz has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/Makefile	Sat Nov 26 14:48:37 2016 +0100
@@ -0,0 +1,58 @@
+DEVICE      = attiny85
+CLOCK      = 8000000
+PROGRAMMER = -c usbasp
+OBJECTS    = main.o
+
+# for ATTiny85
+# see http://www.engbedded.com/fusecalc/
+FUSES       = -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m 
+
+# Tune the lines below only if you know what you are doing:
+AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
+COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)
+
+# symbolic targets:
+all:	main.hex
+
+.c.o:
+	$(COMPILE) -c $< -o $@
+
+.S.o:
+	$(COMPILE) -x assembler-with-cpp -c $< -o $@
+
+.c.s:
+	$(COMPILE) -S $< -o $@
+
+flash:	all
+	$(AVRDUDE) -U flash:w:main.hex:i
+
+fuse:
+	$(AVRDUDE) $(FUSES)
+
+# Xcode uses the Makefile targets "", "clean" and "install"
+install: flash fuse
+
+# if you use a bootloader, change the command below appropriately:
+load: all
+	bootloadHID main.hex
+
+clean:
+	rm -f main.hex main.elf $(OBJECTS)
+
+# file targets:
+main.elf: $(OBJECTS)
+	$(COMPILE) -o main.elf $(OBJECTS)
+
+main.hex: main.elf
+	rm -f main.hex
+	avr-objcopy -j .text -j .data -O ihex main.elf main.hex
+	avr-size --format=avr --mcu=$(DEVICE) main.elf
+# If you have an EEPROM section, you must also create a hex file for the
+# EEPROM and add it to the "flash" target.
+
+# Targets for code debugging and analysis:
+disasm:	main.elf
+	avr-objdump -d main.elf
+
+cpp:
+	$(COMPILE) -E main.c`gg
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/main.c	Sat Nov 26 14:48:37 2016 +0100
@@ -0,0 +1,60 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+#include <util/delay.h>
+
+#define byte unsigned char
+
+const byte FREQ[] = {126, 133, 149, 168, 189, 200, 212, 224};
+
+const byte PROGMEM INTRO_NOTES[] = {
+025, 024, 063, 060, 025, 024, 023, 020, 017, 035, 017, 021, 060, 063, 025, 024,
+063, 060, 017, 021, 020, 017, 034, 035, 034, 020, 000
+};
+
+const byte PROGMEM MELODY_NOTES[] = {
+063, 062, 025, 025, 000, 010, 026, 027, 010, 000, 050, 067, 066, 026, 027, 010,
+027, 025, 023, 022, 025, 023, 027, 025, 010, 027, 010, 065, 063, 022, 025, 023,
+027, 025, 010, 026, 025, 026, 027, 010, 027, 066, 010, 027, 025, 023, 027, 025,
+027, 010, 067, 050, 067, 063, 062, 025, 025, 000, 010, 026, 027, 010, 000, 050,
+067, 066, 026, 027, 010, 027, 025, 023, 022, 025, 023, 027, 025, 010, 027, 010,
+065, 063, 022, 025, 023, 027, 025, 010, 026, 025, 026, 027, 010, 027, 066, 010,
+027, 025, 023, 027, 025, 027, 010, 067, 050, 067, 050, 013, 012, 050, 013, 012,
+010, 027, 025, 010, 024, 025, 024, 023, 050, 050, 013, 012, 010, 013, 024, 025,
+027, 010, 013, 015, 014, 013, 050, 013, 012, 050, 013, 012, 010, 010, 027, 025,
+010, 013, 012, 013, 050, 010, 011, 010, 013, 012, 014, 024, 025, 024, 023, 050,
+051, 050, 013, 012, 050, 013, 012, 010, 027, 025, 010, 024, 025, 024, 023, 050,
+050, 013, 012, 010, 013, 024, 025, 027, 010, 013, 015, 014, 013, 050, 013, 012,
+050, 013, 012, 010, 010, 027, 025, 010, 013, 012, 013, 050, 010, 011, 010, 013,
+012, 010, 024, 025, 024, 023, 050, 067
+};
+
+void play(const byte *notes, byte length) {
+    while (length--) {
+        byte note = pgm_read_byte_near(notes++);
+        byte octave = (note & 0x18) >> 3;
+        if (octave) {
+            TCCR1 = 1<<CTC1 | (8 - octave);
+            OCR1C = FREQ[note & 0x07];
+        }
+        if (note & 0x20) {
+            _delay_ms(220);
+            TCCR1 = 1<<CTC1;
+            _delay_ms(30);
+        } else {
+            _delay_ms(110);
+            TCCR1 = 1<<CTC1;
+            _delay_ms(15);
+        }
+        PORTB ^= 1<<3;
+    }
+}
+
+int main() {
+    DDRB = 1<<4 | 1<<3;
+    GTCCR |= 1<<COM1B0;
+    play(INTRO_NOTES, 26);
+    while(1) {
+        play(MELODY_NOTES, 216);
+    }
+}