Commit db9ad290 by Risto Heinsar

Added wk6 samples and starter code

parent c25092cf
void setup()
{
Serial.begin(9600);
PrintBinaryByte(0b01001101);
PrintBinaryWidth(0xAF2F, 16);
}
void loop()
{
}
void PrintBinaryByte(uint8_t val)
{
for (int i = 7; i >= 0; i--)
{
Serial.print((val >> i) & 1);
}
Serial.println();
}
void PrintBinaryWidth(uint32_t val, uint8_t width)
{
for (int i = width - 1; i >= 0; i--)
{
Serial.print((val >> i) & 1);
if (i % 4 == 0)
{
Serial.print(" ");
}
}
Serial.println();
}
\ No newline at end of file
void setup()
{
Serial.begin(9600);
uint8_t value = 0b00101101;
/* Maskimine valmismaskiga */
uint8_t masked1 = value & 0b11111011;
uint8_t masked2 = value & 0b11011011;
/* Maskimine läbi inverteeritud maski */
uint8_t masked3 = value & ~0b00000100;
uint8_t masked4 = value & ~0b00100100;
Serial.println(masked1, BIN);
Serial.println(masked3, BIN);
Serial.println(masked2, BIN);
Serial.println(masked4, BIN);
}
void loop()
{
}
void setup()
{
Serial.begin(9600);
uint8_t value = 0b00101101;
uint8_t masked1 = value ^ 0b00100000;
uint8_t masked2 = value ^ 0b01100000;
Serial.println(masked1, BIN);
Serial.println(masked2, BIN);
}
void loop()
{
}
void setup()
{
Serial.begin(9600);
uint8_t value = 0b00110101;
/* Muudame paremalt teise biti üheks */
value = bitSet(value, 1);
/* Muudame paremalt kolmanda biti nulliks */
value = bitClear(value, 2);
/* Muudame paremalt kaheksanda biti üheks */
value = bitWrite(value, 7, 1);
Serial.print(value, BIN);
}
void loop()
{
}
void setup()
{
Serial.begin(9600);
uint8_t value = 0b00101101;
uint8_t masked1 = value | 0b00010000;
uint8_t masked2 = value | 0b10010000;
Serial.println(masked1, BIN);
Serial.println(masked2, BIN);
}
void loop()
{
}
void setup()
{
Serial.begin(9600);
uint8_t value = 0b00101101;
/* Tulemus: 10110100*/
uint8_t shifted1 = value << 2;
/* Tulemus: 00000101*/
uint8_t shifted2 = value >> 3;
Serial.println(shifted1, BIN);
Serial.println(shifted2, BIN);
}
void loop()
{
}
void setup()
{
Serial.begin(9600);
uint8_t value = 0b00101101;
uint8_t unpacked = ((value & 0b00111100) >> 2);
Serial.print("Kolmanda kuni kuuenda biti lahtipakkimise tulemus:");
Serial.println(unpacked);
Serial.println(unpacked, BIN);
}
void loop()
{
}
#define BUZZER_PIN 7
void setup()
{
/* Heli genereerimsie näide 1 */
BuzzerWithDelay();
/* Sekund vahet kahele helile */
delay(1000);
/* Heli genereerimsie näide 2 */
BuzzerWithAutomaticTimeout();
}
void loop()
{
}
void BuzzerWithDelay()
{
/* Aktiveeri sumisti soovitud sagedusel */
tone(BUZZER_PIN, 300);
/* Lase helil mängida viite jagu */
delay(500);
/* Lülita sumisti välja */
noTone(BUZZER_PIN);
}
void BuzzerWithAutomaticTimeout()
{
/* Sumisti mängib pool sekundit ja lülitab end ise välja */
tone(BUZZER_PIN, 300, 500);
}
\ No newline at end of file
#define BUZZER_PIN 4
void setup()
{
superMario(BUZZER_PIN);
}
void loop()
{
}
void superMario(uint8_t buzzer)
{
//Intro
tone(buzzer, 660, 100);
delay(150);
tone(buzzer, 660, 100);
delay(300);
tone(buzzer, 660, 100);
delay(300);
tone(buzzer, 510, 100);
delay(300);
tone(buzzer, 660, 100);
delay(300);
tone(buzzer, 770, 150);
delay(500);
tone(buzzer, 380, 100);
delay(575);
// 2. part
tone(buzzer, 510, 100);
delay(450);
tone(buzzer, 380, 100);
delay(400);
tone(buzzer, 320, 100);
delay(500);
tone(buzzer, 440, 100);
delay(300);
tone(buzzer, 480, 80);
delay(330);
tone(buzzer, 450, 100);
delay(150);
tone(buzzer, 430, 100);
delay(300);
tone(buzzer, 380, 100);
delay(200);
tone(buzzer, 660, 80);
delay(200);
tone(buzzer, 760, 50);
delay(150);
tone(buzzer, 860, 100);
delay(300);
tone(buzzer, 700, 80);
delay(150);
tone(buzzer, 760, 50);
delay(350);
tone(buzzer, 660, 80);
delay(300);
tone(buzzer, 520, 80);
delay(150);
tone(buzzer, 580, 80);
delay(150);
tone(buzzer, 480, 80);
delay(500);
// 2. part second run
tone(buzzer, 510, 100);
delay(450);
tone(buzzer, 380, 100);
delay(400);
tone(buzzer, 320, 100);
delay(500);
tone(buzzer, 440, 100);
delay(300);
tone(buzzer, 480, 80);
delay(330);
tone(buzzer, 450, 100);
delay(150);
tone(buzzer, 430, 100);
delay(300);
tone(buzzer, 380, 100);
delay(200);
tone(buzzer, 660, 80);
delay(200);
tone(buzzer, 760, 50);
delay(150);
tone(buzzer, 860, 100);
delay(300);
tone(buzzer, 700, 80);
delay(150);
tone(buzzer, 760, 50);
delay(350);
tone(buzzer, 660, 80);
delay(300);
tone(buzzer, 520, 80);
delay(150);
tone(buzzer, 580, 80);
delay(150);
tone(buzzer, 480, 80);
delay(500);
// some middle part
tone(buzzer, 500, 100);
delay(300);
tone(buzzer, 760, 100);
delay(100);
tone(buzzer, 720, 100);
delay(150);
tone(buzzer, 680, 100);
delay(150);
tone(buzzer, 620, 150);
delay(300);
tone(buzzer, 650, 150);
delay(300);
tone(buzzer, 380, 100);
delay(150);
tone(buzzer, 430, 100);
delay(150);
tone(buzzer, 500, 100);
delay(300);
tone(buzzer, 430, 100);
delay(150);
tone(buzzer, 500, 100);
delay(100);
tone(buzzer, 570, 100);
delay(220);
tone(buzzer, 500, 100);
delay(300);
//skipped a lot
tone(buzzer, 660, 100);
delay(150);
tone(buzzer, 660, 100);
delay(300);
tone(buzzer, 660, 100);
delay(300);
tone(buzzer, 510, 100);
delay(100);
tone(buzzer, 660, 100);
delay(300);
tone(buzzer, 770, 100);
delay(550);
tone(buzzer, 380, 100);
delay(575);
}
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24Network.h>
#include <RF24.h>
#define RADIO_CSN_PIN 10
#define RADIO_CE_PIN 9
#define RADIO_NODE_ADDR 051
#define RADIO_CHANNEL 127
#define TEMPO 250
RF24 g_radio(RADIO_CE_PIN, RADIO_CSN_PIN); // Pin setup for UNO
RF24Network network(g_radio); // Include the radio in the network
void setup()
{
/* Start serial monitor */
Serial.begin(9600);
/* Call radio setup, if failed block code with infinite loop */
if (!RadioSetup()) while (1);
Serial.println("Radio initialized.");
}
void loop()
{
static uint16_t incomingData = 0;
/* To keep the radio network running */
network.update();
/* Setting default header, don't change */
RF24NetworkHeader header_master;
while (network.available())
{
network.read(header_master, &incomingData, sizeof(incomingData)); //Read the network packet
}
}
void PlayToneRadio(int noteTone, int duration)
{
}
/* Radio setup, don't change */
bool RadioSetup()
{
/* Start the radio instance */
if (!g_radio.begin()) return 0;
/* Checking if the radio is connected */
if (!g_radio.isChipConnected()) return 0;
network.begin(RADIO_CHANNEL, RADIO_NODE_ADDR); //(channel, node address)
g_radio.setDataRate(RF24_250KBPS); // RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
g_radio.setPALevel(RF24_PA_LOW); // RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_MED=-6dBM, and RF24_PA_HIGH=0dBm.
g_radio.setAutoAck(false);
return 1;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment