Lab_interaccio/2019/PixelPlayer/PixelPlayer.ino
Miguel Angel de Heras 451795bb92 Second commit
2025-03-05 15:57:19 +01:00

154 lines
4.3 KiB
C++

// include the SD library:
#include <SPI.h>
#include <SD.h>
#include <Adafruit_NeoPixel.h>
#include "nRF24L01MOD.h"
#include "RF24MOD.h"
#include "printfMOD.h"
#include "MCP23008.h"
//Found device at: 0x20
//Found device at: 0xA0
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
const int CS_MMC = 4;
const int CD_MMC = 2;
#define CE_PIN 7
#define CSN_PIN 6
int radioId;
uint32_t CMD[ 8 ]; // CMD + Ch + 2
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
//int ch = 0x4C ; // 76 por defecto es el canal 76 (showroom)
//Definicion de los pines de la tira de led
#define RED 8
#define GREEN 9
#define BLUE 10
#define WHITE 5
//Definicion de los pines de laS tiraS de led PIXELS
#define SDO1 A5
#define SDO2 A2
#define SDO3 A3
MCP23008 id;
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 16 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels_1(NUMPIXELS, SDO1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels_2(NUMPIXELS, SDO2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels_3(NUMPIXELS, SDO3, NEO_GRB + NEO_KHZ800);
void setup() {
// Open SerialUSB communications and wait for port to open:
SerialUSB.begin(9600);
while (!SerialUSB) {
//; // wait for SerialUSB port to connect. Needed for Leonardo only
}
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(WHITE, OUTPUT);
analogWrite(RED, 0);
analogWrite(GREEN, 0);
analogWrite(BLUE, 0);
analogWrite(WHITE, 0);
// while (!SerialUSB) {
// ; // wait for SerialUSB port to connect. Needed for native USB port only
// }
SerialUSB.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
// if (!card.init(SPI_HALF_SPEED, CS_MMC)) {
// SerialUSB.println("initialization failed. Things to check:");
// SerialUSB.println("* is a card inserted?");
// SerialUSB.println("* is your wiring correct?");
// SerialUSB.println("* did you change the chipSelect pin to match your shield or module?");
// //while (1);
// } else {
// SerialUSB.println("Wiring is correct and a card is present.");
// }
//
// //radioId = 0; // MASTER
// radio.begin();
// radio.setDataRate( RF24_250KBPS );
// radio.setPALevel( RF24_PA_MAX );
// radio.setAutoAck(0);
// radio.setPayloadSize(8);
// radio.setChannel(76);
// radio.openReadingPipe(1, pipe);
// radio.startListening();
// radio.printDetails();
// //printf_begin();
// pixels_1.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
// pixels_2.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
// pixels_3.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
// configure MCP23008 component
id.begin(0x20);
id.pinMode(0xFF);
id.setPullup(0xFF);
}
void loop(void) {
SerialUSB.println(id.read());
delay(100);
// for(int i=0; i<=255; i++)
// {
// analogWrite(RED, i);
// delay(10);
// }
// analogWrite(RED, 0);
// for(int i=0; i<=255; i++)
// {
// analogWrite(GREEN, i);
// delay(10);
// }
// analogWrite(GREEN, 0);
// for(int i=0; i<=255; i++)
// {
// analogWrite(BLUE, i);
// delay(10);
// }
// analogWrite(BLUE, 0);
// for(int i=0; i<=255; i++)
// {
// analogWrite(WHITE, i);
// delay(10);
// }
// analogWrite(WHITE, 0);
// pixels_1.clear(); // Set all pixel colors to 'off'
// pixels_2.clear(); // Set all pixel colors to 'off'
// pixels_3.clear(); // Set all pixel colors to 'off'
// // The first NeoPixel in a strand is #0, second is 1, all the way up
// // to the count of pixels minus one.
// for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
// // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
// // Here we're using a moderately bright green color:
// pixels_1.setPixelColor(i, pixels_1.Color(0, 150, 0));
// pixels_2.setPixelColor(i, pixels_2.Color(0, 150, 0));
// pixels_3.setPixelColor(i, pixels_3.Color(0, 150, 0));
// pixels_1.show(); // Send the updated pixel colors to the hardware.
// pixels_2.show(); // Send the updated pixel colors to the hardware.
// pixels_3.show(); // Send the updated pixel colors to the hardware.
// delay(100); // Pause before next pass through loop
// }
}