Cov txheej txheem:

Kev Sib Tw tiag tiag: 5 Kauj Ruam
Kev Sib Tw tiag tiag: 5 Kauj Ruam

Video: Kev Sib Tw tiag tiag: 5 Kauj Ruam

Video: Kev Sib Tw tiag tiag: 5 Kauj Ruam
Video: ib sim hawj kev hlub tag lawm tiag tiag 2020 2024, Hlis ntuj nqeg
Anonim
Image
Image
Kauj ruam 1: Solder Circuit
Kauj ruam 1: Solder Circuit

Lub ntiaj teb niaj hnub xav kom tib neeg tawm ntawm lub cev thiab nyob hauv digital.

Nrog rau qhov pom ntawm Al thiab kev nthuav dav ntawm cov neeg siv thev naus laus zis tso siab rau hauv lub tshuab ntau dhau thiab ntseeg nws ib txwm yog qhov raug.

"Tiag tiag" yog lub hom phiaj txhawm rau txhawm rau qhov kev ntseeg cuav no los ntawm kev tsim cov cuav cuav kuaj ntsuas. Tib neeg yuav yooj yim ntseeg tias tiag tiag tab tom ua haujlwm tab sis thaum muab cov lus teb tsis raug nws yuav ua rau lawv qhov muag tsis pom kev ntseeg hauv thev naus laus zis.

Kauj Ruam 1: Kauj Ruam 1: Tua Hluav Taws Xob

Vim tias kuv txoj haujlwm tsuas muaj ib lub teeb xwb, yog li nws yooj yim heev rau cov laug. Qhov teeb meem tseem ceeb yog thaum pib, Kuv tau siv ob lub teeb, tab sis kuv tsis tau npog qhov raug tam sim ntawd. Yog li thaum ob lub xov hlau txuas ua ke. Nws luv luv.

Kauj Ruam 2: Kauj Ruam 2: Sau Txoj Cai

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; kab-qhov siab: 15.0px; font: 12.0px Lub Sijhawm; xim: #000000; xim tom qab: #ffffff}

p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; kab-qhov siab: 15.0px; font: 12.0px Lub Sijhawm; xim: #000000; xim tom qab: #ffffff; min-height: 14.0px} span.s1 {font-kerning: tsis muaj}

Kauj Ruam 2: Sau Txoj Cai

/*********************************************************************

Nov yog qhov piv txwv rau peb nRF52 raws Bluefruit LE modules

Xaiv ib qho hnub no hauv khw adafruit!

Adafruit nqis peev sijhawm thiab peev txheej muab qhov qhib qhov chaws no, thov txhawb nqa Adafruit thiab qhib qhov khoom kho vajtse los ntawm kev yuav khoom

khoom los ntawm Adafruit!

MIT daim ntawv tso cai, txheeb xyuas LICENSE kom paub ntau ntxiv

Txhua cov ntawv sau saum toj no, thiab lub vijtsam txaws hauv qab no yuav tsum suav nrog

ib qho kev faib tawm tshiab

*********************************************************************

/ Cov duab no yog npaj los siv nrog NeoPixel tswj

// nto hauv Adafruit's Bluefruit LE Txuas daim ntawv thov mobile.

/

/ - Sau thiab nyem qhov kos duab no rau nRF52 Plaub

// - Qhib Bluefruit LE Txuas app

// - Hloov mus rau NeoPixel cov khoom siv hluav taws xob

// - Nyem rau 'txuas' khawm txhawm rau tsim kev sib txuas thiab

// xa cov ntaub ntawv meta txog pixel txheej txheem

// - Siv NeoPixel cov khoom siv los hloov kho cov pixels ntawm koj lub cuab yeej

/* NCO TSEG: Qhov kos duab no xav tau tsawg kawg version 1.1.0 ntawm Adafruit_Neopixel !!! */

#suav nrog

#suav nrog

#suav nrog

#define NEOPIXEL_VERSION_STRING "Neopixel v2.0"

#define PIN 16 / * Tus Pin siv los tsav NeoPixels * /

#define MAXCOMPONENTS 4

uint8_t *pixelBuffer = NULL;

uint8_t dav = 0;

uint8_t qhov siab = 0;

uint8_t taug kev;

uint8_t CheebtsamValue;

bool yog 400Hz;

uint8_t Cheebtsam = 3; // tsuas yog 3 thiab 4 yog qhov tseem ceeb siv tau

Adafruit_NeoPixel neopixel = Adafruit_NeoPixel ();

// Kev Pabcuam BLE

BLEDfu bledfu;

BLEDis bledis;

BLEUart bleuart;

void teeb tsa ()

{

Serial.begin (115200);

thaum (! Serial) ncua (10); // rau nrf52840 nrog haiv neeg usb

Serial.println ("Adafruit Bluefruit Neopixel Test");

Serial.println ("--------------------------------");

Serial.println ();

Serial.println ("Thov txuas nrog siv Bluefruit Txuas LE daim ntawv thov");

// Config Neopixels

neopixel.begin ();

// Thawj Bluefruit

Bluefruit.begin ();

Bluefruit.setTxPower (4); // Txheeb xyuas bluefruit.h rau qhov muaj txiaj ntsig txhawb

Bluefruit.setName ("Bluefruit52");

Bluefruit. Periph.setConnectCallback (txuas_callback);

// Yuav kom zoo ib yam OTA DFU yuav tsum tau ntxiv ua ntej yog tias nws muaj

bledfu.begin ();

// Kho thiab Pib Pabcuam Cov Ntaub Ntawv Qhia

bledis.setManufacturer ("Adafruit Industries");

bledis.setModel ("Bluefruit Feather52");

bledis.begin ();

// Kho thiab pib BLE UART kev pabcuam

bleuart.begin ();

// Teeb tsa thiab pib tshaj tawm

pib Adv ();

}

void startAdv (tsis muaj dab tsi)

{

// Pob ntawv tshaj tawm

Bluefruit. Advertising.addFlags (BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);

Bluefruit. Advertising.addTxPower ();

// Xws li bleuart 128-ntsis uuid

Bluefruit. Advertising.addService (bleuart);

// Secondary Scan Response Packet (yeem)

// Vim tias tsis muaj chaw rau 'Lub Npe' hauv Cov Ntawv Tshaj Tawm

Bluefruit. ScanResponse.addName ();

/* Pib Tshaj Tawm

* - Pab kom pib tshaj tawm yog tias muaj kev sib txuas

* - Lub sijhawm luv: hom nrawm = 20 ms, hom qeeb = 152.5 ms

* - Lub sijhawm siv rau hom nrawm yog 30 vib nas this

* - Pib (ncua sijhawm) nrog sijhawm = 0 yuav tshaj tawm mus ib txhis (kom txog thaum txuas nrog)

*

* Rau kev pom zoo ncua sijhawm tshaj tawm

*

*/

Bluefruit. Advertising.restartOnDisconnect (muaj tseeb);

Bluefruit. Advertising.setInterval (32, 244); // hauv chav ntawm 0.625 ms

Bluefruit. Advertising.setFastTimeout (30); // tus naj npawb ntawm vib nas this hauv hom nrawm

Bluefruit. Advertising.start (0); // 0 = Tsis txhob tso kev tshaj tawm tom qab n vib nas this

}

void connect_callback (uint16_t conn_handle)

{

// Tau txais kev siv rau kev txuas tam sim no

BLEConnection* txuas = Bluefruit. Connection (conn_handle);

char central_name [32] = {0};

connection-> getPeerName (central_name, sizeof (central_name));

Serial.print ("Txuas nrog");

Serial.println (central_name);

Serial.println ("Thov xaiv 'Neopixels' tab, nyem 'Txuas' thiab muaj kev lom zem");

}

void lub voj ()

{

// Echo tau txais cov ntaub ntawv

yog (Bluefruit.connected () && bleuart.notifyEnabled ())

{

int hais kom ua = bleuart.read ();

hloov (hais kom ua) {

rooj plaub 'V': {// Tau txais Version

commandVersion ();

tawg;

}

rooj plaub 'S': {// Teeb qhov ntev, cov khoom siv, txav mus los …

commandSetup ();

tawg;

}

rooj plaub 'C': {// Ntshiab nrog xim

commandClearColor ();

tawg;

}

rooj plaub 'B': {// Teeb Brightness

commandSetBrightness ();

tawg;

}

rooj plaub 'P': {// Teeb Pixel

commandSetPixel ();

tawg;

}

rooj plaub 'Kuv': {// Tau txais cov duab tshiab

commandImage ();

tawg;

}

}

}

}

tsis muaj dab tsi swapBuffers ()

{

uint8_t *base_addr = pixelBuffer;

int pixelIndex = 0;

rau (int j = 0; j <qhov siab; j ++)

{

rau (int i = 0; kuv <width; i ++) {

yog (Cheebtsam == 3) {

neopixel.setPixelColor (pixelIndex, neopixel. Color (*base_addr, *(base_addr+1), *(base_addr+2)));

}

lwm tus {

neopixel.setPixelColor (pixelIndex, neopixel. Color (*base_addr, *(base_addr+1), *(base_addr+2), *(base_addr+3)));

}

base_addr+= cov khoom;

pixelIndex ++;

}

pixelIndex += stride - dav; // Tsiv pixelIndex mus rau kab tom ntej (coj mus rau hauv tus account qhov kev nqis tes ua)

}

neopixel.show ();

}

void commandVersion () {

Serial.println (F ("Command: Version check"));

sendResponse (NEOPIXEL_VERSION_STRING);

}

void commandSetup () {

Serial.println (F ("Command: Setup"));

dav = bleuart.read ();

qhov siab = bleuart.read ();

txav mus = bleuart.read ();

CheebtsamValue = bleuart.read ();

yog 400Hz = bleuart.read ();

neoPixelType pixelType;

pixelType = componentsValue + (is400Hz? NEO_KHZ400: NEO_KHZ800);

components = (componentsValue == NEO_RGB || componentsValue == NEO_RBG || componentsValue == NEO_GRB || componentsValue == NEO_GBR || componentsValue == NEO_BRG || componentsValue == NEO_BGR)? 3: 4;

Serial.printf ("\ tsize: %dx %d / n", dav, qhov siab);

Serial.printf ("\ tstride: %d / n", txav mus);

Serial.printf ("\ tpixelType %d / n", pixelType);

Serial.printf ("\ tcomponents: %d / n", Cheebtsam);

yog (pixelBuffer! = NULL) {

rho tawm pixelBuffer;

}

uint32_t loj = dav*qhov siab;

pixelBuffer = tshiab uint8_t [qhov loj me*Cheebtsam];

neopixel.updateLength (loj);

neopixel.updateType (pixelType);

neopixel.setPin (PIN);

// Ua tau

sendResponse ("OK");

}

void commandSetBrightness () {

Serial.println (F ("Command: SetBrightness"));

// Nyeem tus nqi

uint8_t ci ntsa iab = bleuart.read ();

// Teeb ci ntsa iab

neopixel.setBrightness (ci ntsa iab);

// Refresh pixels

swapBuffers ();

// Ua tau

sendResponse ("OK");

}

void commandClearColor () {

Serial.println (F ("Command: ClearColor"));

// Nyeem xim

uint8_t xim [MAXCOMPONENTS];

rau (int j = 0; j <components;) {

yog (bleuart.available ()) {

xim [j] = bleuart.read ();

j ++;

}

}

// Teeb tag nrho cov leds rau xim

int loj = dav * qhov siab;

uint8_t *base_addr = pixelBuffer;

rau (int kuv = 0; kuv <loj; kuv ++) {

rau (int j = 0; j <components; j ++) {

*base_addr = xim [j];

base_addr ++;

}

}

// Hloov pauv

Serial.println (F ("ClearColor ua tiav"));

swapBuffers ();

yog (Cheebtsam == 3) {

Serial.printf ("\ tclear (%d, %d, %d) n", xim [0], xim [1], xim [2]);

}

lwm tus {

Serial.printf ("\ tclear (%d, %d, %d, %d) n", xim [0], xim [1], xim [2], xim [3]);

}

// Ua tau

sendResponse ("OK");

}

void commandSetPixel () {

Serial.println (F ("Command: SetPixel"));

// Nyeem txoj haujlwm

uint8_t x = bleuart.read ();

uint8_t y = bleuart.read ();

// Nyeem xim

uint32_t pixelOffset = y*dav+x;

uint32_t pixelDataOffset = pixelOffset*Cheebtsam;

uint8_t *base_addr = pixelBuffer+pixelDataOffset;

rau (int j = 0; j <components;) {

yog (bleuart.available ()) {

*base_addr = bleuart.read ();

base_addr ++;

j ++;

}

}

// Teeb xim

uint32_t neopixelIndex = y*stride+x;

uint8_t *pixelBufferPointer = pixelBuffer + pixelDataOffset;

uint32_t xim;

yog (Cheebtsam == 3) {

xim = neopixel. Color (*pixelBufferPointer, *(pixelBufferPointer+1), *(pixelBufferPointer+2));

Serial.printf ("\ tcolor (%d, %d, %d) n", *pixelBufferPointer, *(pixelBufferPointer+1), *(pixelBufferPointer+2));

}

lwm tus {

xim = neopixel. Color (*pixelBufferPointer, *(pixelBufferPointer+1), *(pixelBufferPointer+2), *(pixelBufferPointer+3));

Serial.printf ("\ tcolor (%d, %d, %d, %d) n", *pixelBufferPointer, *(pixelBufferPointer+1), *(pixelBufferPointer+2), *(pixelBufferPointer+3));

}

neopixel.setPixelColor (neopixelIndex, xim);

neopixel.show ();

// Ua tau

sendResponse ("OK");

}

void commandImage () {

Serial.printf ("Hais kom ua: Duab %dx %d, %d, %d / n", qhov dav, qhov siab, cov khoom siv, txav mus los);

// Tau txais pixel tshiab tsis

int loj = dav * qhov siab;

uint8_t *base_addr = pixelBuffer;

rau (int kuv = 0; kuv <loj; kuv ++) {

rau (int j = 0; j <components;) {

yog (bleuart.available ()) {

*base_addr = bleuart.read ();

base_addr ++;

j ++;

}

}

/*

yog (Cheebtsam == 3) {

uint32_t index = i*cov khoom;

Serial.printf ("\ tp %d (%d, %d, %d) n", i, pixelBuffer [index], pixelBuffer [index+1], pixelBuffer [index+2]);

}

*/

}

// Hloov pauv

Serial.println (F ("Duab tau txais"));

swapBuffers ();

// Ua tau

sendResponse ("OK");

}

void sendResponse (char const *teb) {

Serial.printf ("Xa Cov Lus Teb: %s / n", teb);

bleuart.write (teb, strlen (teb)*sizeof (char));

}

Kauj Ruam 3: Kauj Ruam 3: Yuav Lub Teeb

Kauj Ruam 3: Yuav Lub Teeb
Kauj Ruam 3: Yuav Lub Teeb
Kauj Ruam 3: Yuav Lub Teeb
Kauj Ruam 3: Yuav Lub Teeb

Kauj Ruam 4: Kauj Ruam 4: Rub Nws Txhua Qhov Ua Ke

Pom zoo: