first commit

This commit is contained in:
Zenn 2023-08-06 18:14:49 +02:00
commit c591b2c272
50 changed files with 2650 additions and 0 deletions

View file

@ -0,0 +1,11 @@
[package]
name = "demo2"
version = "0.1.0"
authors = ["ZennDev <zenndev@protonmail.com>"]
edition = "2021"
[lib]
crate-type = ["staticlib"]
[dependencies]
arduboy-rust = "1.0.0"

View file

@ -0,0 +1,18 @@
#![no_std]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
//The setup() function runs once when you turn your Arduboy on
#[no_mangle]
pub unsafe extern "C" fn setup() {
// put your setup code here, to run once:
arduboy.begin();
arduboy.clear();
arduboy.print("Holmes is cool!\0");
arduboy.display();
}
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
// put your main code here, to run repeatedly:
}

View file

@ -0,0 +1,11 @@
[package]
name = "demo3"
version = "0.1.0"
authors = ["ZennDev <zenndev@protonmail.com>"]
edition = "2021"
[lib]
crate-type = ["staticlib"]
[dependencies]
arduboy-rust = "1.0.0"

View file

@ -0,0 +1,38 @@
#![no_std]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
//Initialize our counter variable
#[allow(non_upper_case_globals)]
static mut counter: c_int = 0;
//The setup() function runs once when you turn your Arduboy on
#[no_mangle]
pub unsafe extern "C" fn setup() {
//Start the Arduboy properly and display the Arduboy logo
arduboy.begin();
//Get rid of the Arduboy logo and clear the screen
arduboy.clear();
//Assign our counter variable to be equal to 0
counter = 0;
//Set framerate to 30
arduboy.set_frame_rate(30);
}
//The loop() function repeats forever after setup() is done
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
//Skip cycles not in the framerate
if !arduboy.next_frame() {
return;
}
//Clear whatever is printed on the screen
arduboy.clear();
//Move the cursor to the position 30, 30 of the screen
arduboy.set_cursor(0, 0);
//Increase counter's value by 1
counter += 1;
//Print out the value of counter
arduboy.print(counter);
//Refresh the screen to show whatever's printed to it
arduboy.display();
}

View file

@ -0,0 +1,11 @@
[package]
name = "demo4"
version = "0.1.0"
authors = ["ZennDev <zenndev@protonmail.com>"]
edition = "2021"
[lib]
crate-type = ["staticlib"]
[dependencies]
arduboy-rust = "1.0.0"

View file

@ -0,0 +1,54 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
//Initialize our counter variable
static mut counter: c_int = 0;
//The setup() function runs once when you turn your Arduboy on
#[no_mangle]
pub unsafe extern "C" fn setup() {
//Start the Arduboy properly and display the Arduboy logo
arduboy.begin();
//Get rid of the Arduboy logo and clear the screen
arduboy.clear();
//Assign our counter variable to be equal to 0
counter = 0;
//Set framerate to 10
arduboy.set_frame_rate(10);
}
//The loop() function repeats forever after setup() is done
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
//Skip cycles not in the framerate
if !arduboy.next_frame() {
return;
}
//Clear whatever is printed on the screen
arduboy.clear();
//Check if the UP_BUTTON is being pressed
if UP.pressed() {
//Increase counter by 1
counter = counter + 1;
}
//Check if the DOWN_BUTTON is being pressed
if DOWN.pressed() {
//Decrease counter
counter = counter - 1;
}
//Check if counter is equal to 36
if counter == 36 {
//Move the cursor to the position 30, 30 of the screen
arduboy.set_cursor(30, 30);
//Printing the yay (important always put the \0 at the end for &str)
arduboy.print("Yay!\0");
}
//Move the cursor back to the top-left of the screen
arduboy.set_cursor(0, 0);
//Print out the value of counter
arduboy.print(counter);
//Refresh the screen to show whatever's printed to it
arduboy.display();
}

View file

@ -0,0 +1,10 @@
[package]
name = "demo5"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["staticlib"]
[dependencies]
arduboy-rust = "1.0.0"

View file

@ -0,0 +1,95 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::prelude::*;
//Initialize variables used in this game
static mut playerwin: c_int = 0;
static mut attempts: c_int = 0;
static mut guessednumber: c_int = 0;
static mut randomnumber: c_int = 0;
static mut lastguess: c_int = 0;
//The setup() function runs once when you turn your Arduboy on
#[no_mangle]
pub unsafe extern "C" fn setup() {
// put your setup code here, to run once:
arduboy.begin();
arduboy.clear();
arduboy.init_random_seed();
randomnumber = random_between(1, 101) as i16;
}
//The loop() function repeats forever after setup() is done
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
// put your main code here, to run repeatedly:
arduboy.clear();
arduboy.poll_buttons();
if playerwin == 0 {
//Ask the player for a number and play the game
if attempts == 7 {
//Game Over screen
arduboy.set_cursor(0, 0);
arduboy.print("You lost!\0");
arduboy.print("\n\0");
arduboy.print("Correct Number: \0");
arduboy.print(randomnumber);
if A.just_pressed() {
randomnumber = random_between(1, 101) as i16;
attempts = 0;
playerwin = 0;
}
} else {
//Player has more attempts
if UP.just_pressed() {
guessednumber += 1;
}
if DOWN.just_pressed() {
guessednumber -= 1;
}
if A.just_pressed() {
if guessednumber == randomnumber {
playerwin += 1;
} else {
attempts += 1;
lastguess = guessednumber
}
}
arduboy.set_cursor(0, 0);
arduboy.print("Attempt: \0");
arduboy.print(attempts);
arduboy.print("\n\0");
arduboy.print("Number to guess: \0");
arduboy.print(guessednumber);
arduboy.print("\n\0");
if attempts == 0 {
arduboy.print("Good luck!\0");
} else {
arduboy.print(lastguess);
if lastguess > randomnumber {
arduboy.print(" is too high!\0");
}
if lastguess < randomnumber {
arduboy.print(" is too low!\0");
}
}
}
} else {
//Tell the player that they won!
arduboy.set_cursor(0, 0);
arduboy.print("You won!\0");
arduboy.print("\n\0");
arduboy.print("Correct Number: \0");
arduboy.print(randomnumber);
if A.just_pressed() {
randomnumber = random_between(1, 101) as c_int;
attempts = 0;
playerwin = 0;
}
}
arduboy.display();
}

View file

@ -0,0 +1,10 @@
[package]
name = "demo6"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["staticlib"]
[dependencies]
arduboy-rust = "1.0.0"

View file

@ -0,0 +1,76 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
#[allow(unused_imports)]
use arduboy_rust::prelude::*;
#[link_section = ".progmem.data"]
static background_sprite: [u8; 10] = [8, 8, 0x81, 0x00, 0x12, 0x40, 0x04, 0x11, 0x00, 0x04];
#[link_section = ".progmem.data"]
static player_sprite1: [u8; 34] = [
16, 16, 0xfe, 0x01, 0x3d, 0x25, 0x25, 0x3d, 0x01, 0x01, 0xc1, 0x01, 0x3d, 0x25, 0x25, 0x3d,
0x01, 0xfe, 0x7f, 0x80, 0x9c, 0xbc, 0xb0, 0xb0, 0xb2, 0xb2, 0xb3, 0xb0, 0xb0, 0xb0, 0xbc, 0x9c,
0x80, 0x7f,
];
#[link_section = ".progmem.data"]
static player_sprite2: [u8; 34] = [
16, 16, 0xfc, 0x02, 0x19, 0x25, 0x25, 0x19, 0x01, 0x01, 0x01, 0x01, 0x19, 0x25, 0x25, 0x19,
0x02, 0xfc, 0x3f, 0x40, 0x80, 0x98, 0x8c, 0x86, 0x82, 0x82, 0x82, 0x82, 0x86, 0x8c, 0x98, 0x80,
0x40, 0x3f,
];
// Put your variables here
static mut playerx: c_int = 5;
static mut playery: c_int = 10;
static mut playermode: bool = false;
// The setup() function runs once when you turn your Arduboy on
#[no_mangle]
pub unsafe extern "C" fn setup() {
// put your setup code here, to run once:
arduboy.begin();
arduboy.clear();
arduboy.set_frame_rate(60);
}
// The loop() function repeats forever after setup() is done
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
if !arduboy.next_frame() {
return;
}
// put your main code here, to run repeatedly:
arduboy.clear();
arduboy.poll_buttons();
if arduboy.pressed(LEFT) {
playerx -= 1;
}
if arduboy.pressed(RIGHT) {
playerx += 1;
}
if arduboy.pressed(UP) {
playery -= 1;
}
if arduboy.pressed(DOWN) {
playery += 1;
}
if arduboy.just_pressed(A) {
playermode = !playermode
}
for i in (0..WIDTH).step_by(8) {
for j in (0..HEIGHT).step_by(8) {
sprites::draw_override(i.into(), j.into(), get_sprite_addr!(background_sprite), 0)
}
}
if playermode {
sprites::draw_override(playerx, playery, get_sprite_addr!(player_sprite1), 0);
} else {
sprites::draw_override(playerx, playery, get_sprite_addr!(player_sprite2), 0);
}
arduboy.set_cursor(0, 0);
arduboy.display();
}

View file

@ -0,0 +1,12 @@
[package]
name = "eeprom-demo"
version = "0.1.0"
authors = ["ZennDev <zenndev@protonmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
[lib]
crate-type = ["staticlib"]
[dependencies]
arduboy-rust = "1.0.0"

View file

@ -0,0 +1,59 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
#[allow(unused_imports)]
use arduboy_rust::prelude::*;
// #[link_section = ".progmem.data"]
// Setup eeprom memory
static mut eeprom: EEPROM = EEPROM::new(10);
static mut count: u8 = 0;
static mut MEM: u8 = 0;
// The setup() function runs once when you turn your Arduboy on
#[no_mangle]
pub unsafe extern "C" fn setup() {
// put your setup code here, to run once:
arduboy.begin();
eeprom.init();
arduboy.clear();
arduboy.set_frame_rate(30);
}
// The loop() function repeats forever after setup() is done
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
// put your main code here, to run repeatedly:
if !arduboy.next_frame() {
return;
}
arduboy.clear();
arduboy.poll_buttons();
if arduboy.just_pressed(UP) {
count += 1;
}
if arduboy.just_pressed(DOWN) {
count -= 1;
}
if arduboy.just_pressed(A) {
unsafe { eeprom.put(count) }
}
if arduboy.just_pressed(B) {
eeprom.get(&mut MEM)
}
arduboy.set_cursor(0, 0);
arduboy.print(count as u16);
arduboy.set_cursor(0, 30);
arduboy.print("Memory:\0");
arduboy.print(MEM as u16);
arduboy.set_cursor(0, 40);
arduboy.print("eeprom:\0");
arduboy.print(eeprom.read() as u16);
arduboy.display();
}

View file

@ -0,0 +1,12 @@
[package]
name = "tone"
version = "0.1.0"
authors = ["ZennDev <zenndev@protonmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
[lib]
crate-type = ["staticlib"]
[dependencies]
arduboy-rust = "1.0.0"

View file

@ -0,0 +1,490 @@
#![no_std]
#![allow(non_upper_case_globals)]
//Include the Arduboy Library
//Initialize the arduboy object
use arduboy_rust::arduboy_tone_pitch::*;
#[allow(unused_imports)]
use arduboy_rust::prelude::*;
#[link_section = ".progmem.data"]
static allNotes: [u16; 241] = [
NOTE_C0H,
NDUR,
NOTE_CS0,
NDUR,
NOTE_D0,
NDUR,
NOTE_DS0,
NDUR,
NOTE_E0,
NDUR,
NOTE_F0,
NDUR,
NOTE_FS0,
NDUR,
NOTE_G0,
NDUR,
NOTE_GS0,
NDUR,
NOTE_A0,
NDUR,
NOTE_AS0,
NDUR,
NOTE_B0,
NDUR,
NOTE_C1H,
NDUR,
NOTE_CS1,
NDUR,
NOTE_D1,
NDUR,
NOTE_DS1,
NDUR,
NOTE_E1,
NDUR,
NOTE_F1,
NDUR,
NOTE_FS1,
NDUR,
NOTE_G1,
NDUR,
NOTE_GS1,
NDUR,
NOTE_A1,
NDUR,
NOTE_AS1,
NDUR,
NOTE_B1,
NDUR,
NOTE_C2H,
NDUR,
NOTE_CS2,
NDUR,
NOTE_D2,
NDUR,
NOTE_DS2,
NDUR,
NOTE_E2,
NDUR,
NOTE_F2,
NDUR,
NOTE_FS2,
NDUR,
NOTE_G2,
NDUR,
NOTE_GS2,
NDUR,
NOTE_A2,
NDUR,
NOTE_AS2,
NDUR,
NOTE_B2,
NDUR,
NOTE_C3H,
NDUR,
NOTE_CS3,
NDUR,
NOTE_D3,
NDUR,
NOTE_DS3,
NDUR,
NOTE_E3,
NDUR,
NOTE_F3,
NDUR,
NOTE_FS3,
NDUR,
NOTE_G3,
NDUR,
NOTE_GS3,
NDUR,
NOTE_A3,
NDUR,
NOTE_AS3,
NDUR,
NOTE_B3,
NDUR,
NOTE_C4H,
NDUR,
NOTE_CS4,
NDUR,
NOTE_D4,
NDUR,
NOTE_DS4,
NDUR,
NOTE_E4,
NDUR,
NOTE_F4,
NDUR,
NOTE_F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AT,
];
#[link_section = ".progmem.data"]
static sound1: [u16; 73] = [
NOTE_C1, 500, NOTE_C1H, 500, NOTE_G1, 500, NOTE_G1H, 500, NOTE_C2, 500, NOTE_C2H, 500, NOTE_G2,
500, NOTE_G2H, 500, NOTE_C3, 500, NOTE_C3H, 500, NOTE_G3, 500, NOTE_G3H, 500, NOTE_C4, 500,
NOTE_C4H, 500, NOTE_G4, 500, NOTE_G4H, 500, NOTE_C5, 500, NOTE_C5H, 500, NOTE_G5, 500,
NOTE_G5H, 500, NOTE_C6, 500, NOTE_C6H, 500, NOTE_G6, 500, NOTE_G6H, 500, NOTE_C7, 500,
NOTE_C7H, 500, NOTE_G7, 500, NOTE_G7H, 500, NOTE_C8, 500, NOTE_C8H, 500, NOTE_G8, 500,
NOTE_G8H, 500, NOTE_C9, 500, NOTE_C9H, 500, NOTE_G9, 500, NOTE_G9H, 500, TONES_END,
];
static mut circle_pos: i16 = 7;
const BUTTON_DELAY: u32 = 200;
// The setup() function runs once when you turn your Arduboy on
#[no_mangle]
pub unsafe extern "C" fn setup() {
// put your setup code here, to run once:
arduboy.begin();
}
// The loop() function repeats forever after setup() is done
#[no_mangle]
#[export_name = "loop"]
pub unsafe extern "C" fn loop_() {
let mut in_ram: [u16; 43] = [
NOTE_E4,
400,
NOTE_D4,
200,
NOTE_C4,
400,
NOTE_REST,
200,
NOTE_D4,
200,
NOTE_C4,
300,
NOTE_REST,
100,
NOTE_C4,
300,
NOTE_REST,
100,
NOTE_E4,
300,
NOTE_REST,
100,
NOTE_G4,
300,
NOTE_REST,
100,
NOTE_F4,
300,
NOTE_REST,
100,
NOTE_A4,
300,
NOTE_REST,
100,
NOTE_D5H,
200,
NOTE_REST,
200,
NOTE_D5H,
200,
NOTE_REST,
1500,
TONES_REPEAT,
];
// put your main code here, to run repeatedly:
let mut new_notes: bool;
display_audio();
loop {
move_circle();
if arduboy.pressed(UP) {
arduboy.audio_on();
display_audio();
}
if arduboy.pressed(DOWN) {
arduboy.audio_off();
display_audio();
}
if arduboy.pressed(B) {
delay(BUTTON_DELAY);
break;
}
}
sound.tone(1000, 0);
arduboy.clear();
arduboy.print("tone(1000)\n\nB: no_tone()\n delay(1000)\n break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
sound.no_tone();
delay(1000);
break;
}
}
sound.tone(500, 4000);
arduboy.clear();
arduboy.print("tone(500, 4000)\n\nB: break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
delay(BUTTON_DELAY);
break;
}
}
sound.tone2(NOTE_C4, 500, NOTE_C5H, 5000);
arduboy.clear();
arduboy.print("tone(C4,500,C5H,5000)\n\nB: no_tone(), break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
sound.no_tone();
delay(BUTTON_DELAY);
break;
}
}
sound.tone3(NOTE_C7H, 500, NOTE_REST, 1000, NOTE_C6, 5000);
arduboy.clear();
arduboy.print("tone(C7H,500,\n REST,1000,\n C6,6000)\n\nB: no_tone(), break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(B_BUTTON) {
sound.no_tone();
delay(BUTTON_DELAY);
break;
}
}
sound.tones(get_tones_addr!(allNotes));
arduboy.clear();
arduboy.print("tones(allNotes)\n\nA: no_tone(), again\nUP: again\nB: break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(A_BUTTON) {
sound.no_tone();
sound.tones(get_tones_addr!(allNotes));
}
if arduboy.pressed(UP_BUTTON) {
sound.tones(get_tones_addr!(allNotes));
}
if arduboy.pressed(B_BUTTON) {
delay(BUTTON_DELAY);
break;
}
}
new_notes = false;
sound.tones_in_ram(get_tones_addr!(in_ram) as *mut u32);
arduboy.clear();
arduboy.print("tonesInRAM(inRAM)\n\nA: change notes\nB: break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(A_BUTTON) {
new_notes = !new_notes;
if new_notes {
in_ram[34] = in_ram[38];
in_ram[38] = NOTE_C5H;
} else {
in_ram[34] = in_ram[38];
in_ram[38] = NOTE_D5H;
}
delay(BUTTON_DELAY);
}
if arduboy.pressed(B) {
delay(BUTTON_DELAY);
break;
}
}
sound.tones(get_tones_addr!(sound1));
arduboy.clear();
arduboy.print("volume_mode(IN_TONES)\ntones(sound1)\n\nB: break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(B) {
delay(BUTTON_DELAY);
break;
}
}
sound.volume_mode(VOLUME_ALWAYS_NORMAL);
sound.tones(get_tones_addr!(sound1));
arduboy.clear();
arduboy.print("volume_mode(NORMAL)\ntones(sound1)\n\nB: no_tone(), break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(B) {
sound.no_tone();
delay(BUTTON_DELAY);
break;
}
}
sound.volume_mode(VOLUME_ALWAYS_HIGH);
sound.tones(get_tones_addr!(sound1));
arduboy.clear();
arduboy.print("volume_mode(HIGH)\ntones(sound1)\n\nB: break\0");
while sound.playing() {
move_circle();
if arduboy.pressed(B) {
delay(BUTTON_DELAY);
break;
}
}
sound.volume_mode(VOLUME_IN_TONE);
}
fn move_circle() {
unsafe {
arduboy.fill_circle(circle_pos, 54, 7, Color::Black);
circle_pos += 8;
if circle_pos > 119 {
circle_pos = 7;
}
arduboy.fill_circle(circle_pos, 54, 7, Color::White);
}
arduboy.display();
delay(100);
}
fn display_audio() {
arduboy.clear();
arduboy.print("Audio enabled: \0");
if arduboy.audio_enabled() {
arduboy.print("YES\0");
} else {
arduboy.print("NO\0")
}
arduboy.print("\n\nUP: enable\nDOWN: disable\nB: break\0");
arduboy.invert(!arduboy.audio_enabled());
}