Ср июл 06, 2022 08:26:48
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight();
}
void loop()
{
if (mySwitch.available()) {
lcd.setCursor(0,0);
lcd.print("Received ");
lcd.print( mySwitch.getReceivedValue() );
lcd.print(" / ");
lcd.print( mySwitch.getReceivedBitlength() );
lcd.setCursor(0,1);
lcd.print("bit ");
lcd.print("Protocol: ");
lcd.print( mySwitch.getReceivedProtocol() );
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
mySwitch.resetAvailable();
}
}
Ср июл 06, 2022 08:36:31
Ср июл 06, 2022 08:53:02
Ср июл 06, 2022 08:56:07
Ср июл 06, 2022 10:53:36
electroget писал(а):Но не совсем понятно
Ср июл 06, 2022 17:54:07
Ср июл 06, 2022 23:22:08
Вт июл 19, 2022 19:57:01
/*
Steps:
1. Edit pcmConfig.h
a: On Uno or non-mega boards, #define buffSize 128. May need to increase.
b: Uncomment #define ENABLE_RECORDING and #define BLOCK_COUNT 10000UL
2. Usage is as below. See https://github.com/TMRh20/TMRpcm/wiki/Advanced-Features#wiki-recording-audio for
additional informaiton.
*/
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 4
TMRpcm audio;
int audiofile = 0;
unsigned long i = 0;
bool recmode = 0;
int RecPressed=0;
int StopPressed=0;
void setup() {
pinMode(A0, INPUT);
pinMode(6, OUTPUT);
pinMode(5, INPUT_PULLUP);
//attachInterrupt(0, button, LOW);
SD.begin(SD_ChipSelectPin);
audio.CSPin = SD_ChipSelectPin;
audio.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
audio.play("001251.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
}
void loop() {
if (digitalRead(5)==LOW && RecPressed==0)
{digitalWrite(6, HIGH);StartRec();}
else if (digitalRead(5)==HIGH && RecPressed==1)
{digitalWrite(6, LOW);StopRec();}
}
void StartRec() {
RecPressed=1;
audiofile++;
switch (audiofile) {
case 1: audio.startRecording("1.wav", 16000, A0); break;
}
}
void StopRec() {
RecPressed=0;
recmode = 0;
//digitalWrite(6, LOW);
switch (audiofile) {
case 1: audio.stopRecording("1.wav"); break;
}
}
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
Ср июл 20, 2022 20:59:09
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
/**
* Channel scanner
*
* Example to detect interference on the various channels available.
* This is a good diagnostic tool to check whether you're picking a
* good channel for your application.
*
* Inspired by cpixip.
* See http://arduino.cc/forum/index.php/topic,54795.0.html
*/
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
//
// Hardware configuration
//
// Set up nRF24L01 radio on SPI bus plus pins 7 & 8
RF24 radio(9,10);
//
// Channel info
//
const uint8_t num_channels = 128;
uint8_t values[num_channels];
//
// Setup
//
void setup(void)
{
//
// Print preamble
//
Serial.begin(115200);
printf_begin();
printf("\n\rRF24/examples/scanner/\n\r");
//
// Setup and configure rf radio
//
radio.begin();
radio.setAutoAck(false);
// Get into standby mode
radio.startListening();
radio.stopListening();
// Print out header, high then low digit
int i = 0;
while ( i < num_channels )
{
printf("%x",i>>4);
++i;
}
printf("\n\r");
i = 0;
while ( i < num_channels )
{
printf("%x",i&0xf);
++i;
}
printf("\n\r");
}
//
// Loop
//
const int num_reps = 100;
void loop(void)
{
// Clear measurement values
memset(values,0,sizeof(values));
// Scan all channels num_reps times
int rep_counter = num_reps;
while (rep_counter--)
{
int i = num_channels;
while (i--)
{
// Select this channel
radio.setChannel(i);
// Listen for a little
radio.startListening();
delayMicroseconds(225);
// Did we get a carrier?
if ( radio.testCarrier() ){
++values[i];
}
radio.stopListening();
}
}
// Print out channel measurements, clamped to a single hex digit
int i = 0;
while ( i < num_channels )
{
printf("%x",min(0xf,values[i]&0xf));
++i;
}
printf("\n\r");
}
// vim:ai:cin:sts=2 sw=2 ft=cpp
Вт авг 30, 2022 15:47:56