Related
I'm trying to make a project using the 16x32 RGB Led matrix, from the Adafruit store, but for some reason Visual Studio keeps telling me I've defined the matrix class multiple times.
This all started happening when I started making my own classes for my program (I'm still learning OOP). I have put define protection in the header file where I instantiate the matrix class, so that shouldn't be the problem
I've tried moving the class definition around. When I put it into the cpp file where I wanted to use it I stopped getting the multiple definition error, but then the matrix doesn't draw anything.
I've tried parsing a pointer to the matrix class to the class where I wanted to use the matrix but then I get this weird error where the matrix redraws the first thing it has to draw over and over again and it stops responding to serial input/doesn't give any serial output.
code:
//===========Matrix.h===========
#ifndef MATRIX_H
#define MATRIX_H
#include "RGBmatrixPanel.h"
#include <SPI.h>
#include <Adafruit_I2CDevice.h>
#define CLK 8
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
#endif
//===========main.cpp===========
#include <Arduino.h>
#include "GuiDrawer.h"
GuiDrawer guiDrawer;
void setup() {
Serial.begin(9600);
guiDrawer.drawBaseGui();
}
void loop() {}
//===========GuiDrawer.h===========
#ifndef GUIDRAWER_H
#define GUIDRAWER_H
#include <Arduino.h>
#include "matrix.h"
class GuiDrawer {
private:
enum COLOURS {
BLACK = 0, //0
WHITE, //1
RED, //2
YELLOW, //3
DARKER_YELLOW, //4
DARKEST_YELLOW, //5
GRAY //6
};
enum SHAPES {
HEART = 0, //0
AMMO, //1
COIN //2
};
const int HEARTSIZE_X = 8;
const int HEARTSIZE_Y = 8;
const int HEARTSHAPE [8][8] = {
{0, 2, 2, 0, 0, 2, 2, 0},
{2, 2, 1, 2, 2, 2, 2, 2},
{2, 1, 2, 2, 2, 2, 2, 2},
{2, 1, 2, 2, 2, 2, 2, 2},
{2, 2, 2, 2, 2, 2, 2, 2},
{0, 2, 2, 2, 2, 2, 2, 0},
{0, 0, 2, 2, 2, 2, 0, 0},
{0, 0, 0, 2, 2, 0, 0, 0},
};
const int COINSIZE_X = 8;
const int COINSIZE_Y = 7;
const int COINSHAPE [8][7] = {
{0, 0, 4, 4, 4, 0, 0},
{0, 4, 3, 3, 3, 4, 0},
{4, 3, 3, 4, 3, 3, 4},
{4, 3, 3, 4, 3, 3, 4},
{4, 3, 3, 4, 3, 3, 4},
{4, 3, 3, 4, 3, 3, 4},
{0, 4, 3, 3, 3, 4, 0},
{0, 0, 4, 4, 4, 0, 0}
};
const int AMMOSIZE_X = 8;
const int AMMOSIZE_Y = 6;
const int AMMOSHAPE [8][6] = {
{0, 6, 0, 0, 6, 0},
{6, 6, 6, 6, 6, 6},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5},
{3, 3, 5, 3, 3, 5}
};
void drawShape(SHAPES shape, int startX, int startY);
void pixelDrawer(COLOURS colourToDraw, int drawX, int drawY);
public:
GuiDrawer();
void drawBaseGui();
};
#endif
//===========GuiDrawer.cpp===========
#include <Arduino.h>
#include "GuiDrawer.h"
GuiDrawer::GuiDrawer() {
matrix.begin();
Serial.begin(9600);
}
void GuiDrawer::drawBaseGui() {
drawShape(HEART, 0, 0);
drawShape(COIN, 0, 8);
drawShape(COIN, 25, 8);
Serial.println("drawn base gui");
}
void GuiDrawer::drawShape(SHAPES shape, int startX, int startY) {
switch (shape) {
case HEART:
for (int i = 0; i < HEARTSIZE_X; i++) {
for (int j = 0; j < HEARTSIZE_Y; j++) {
COLOURS pixelToDraw = (COLOURS)HEARTSHAPE[i][j];
pixelDrawer(pixelToDraw, (j + startX), (i + startY));
}
Serial.println();
}
break;
case AMMO:
for (int i = 0; i < AMMOSIZE_X; i++) {
for (int j = 0; j < AMMOSIZE_Y; j++) {
COLOURS pixelToDraw = (COLOURS)AMMOSHAPE[i][j];
pixelDrawer(pixelToDraw, (j + startX), (i + startY));
}
}
break;
case COIN:
for (int i = 0; i < COINSIZE_X; i++) {
for (int j = 0; j < COINSIZE_Y; j++) {
COLOURS pixelToDraw = (COLOURS)COINSHAPE[i][j];
pixelDrawer(pixelToDraw, (j + startX), (i + startY));
}
}
break;
default:
break;
}
}
void GuiDrawer::pixelDrawer(COLOURS colourToDraw, int drawX, int drawY) {
switch (colourToDraw) {
case BLACK:
matrix.drawPixel(drawX, drawY, matrix.Color333(0, 0, 0));
Serial.print("black ");
break;
case WHITE:
matrix.drawPixel(drawX, drawY, matrix.Color333(255, 255, 255));
Serial.print("white ");
break;
case RED:
matrix.drawPixel(drawX, drawY, matrix.Color333(255, 0, 0));
Serial.print("red ");
break;
case YELLOW:
matrix.drawPixel(drawX, drawY, matrix.Color333(255, 255, 0));
break;
case DARKER_YELLOW:
matrix.drawPixel(drawX, drawY, matrix.Color888(16, 16, 0));
break;
default:
break;
}
}
error I am getting:
.pio\build\uno\src\main.cpp.o (symbol from plugin): In function `matrix':
(.text+0x0): multiple definition of `matrix'
.pio\build\uno\src\GuiDrawer.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1
led matrix: https://www.adafruit.com/product/420
I am trying to output a song using the Piezoelectric buzzer on my Arduino. Running the code without RTOS functionalities works well, however, when i place the code into an RTOS task, the buzzer does not work. I am buzzled by this.
Running the code without RTOS Task function works but when implemented with RTOS, it doesn't work. It seems like the tone() function does not execute.
#include <Arduino.h>
#include <avr/io.h>
#include <FreeRTOS.h>
#include <task.h>
//Tones
#define d 294 // 294 Hz
#define e 329 // 329 Hz
#define fSharp 370 // 369.994 Hz
#define g 392 // 392 Hz
// Define a special note, 'R', to represent a rest
#define R 000
#define babySharkOutput 11
int babyShark[] = { //Note of the song, 0 is a rest/pulse
d, e, g, g, g, g, g, g,
d, e, g, g, g, g, g, g,
d, e, g, g, g, g, g, g,
g, g, fSharp, R
};
int babySharkDuration[] = {
400, 200, 50, 50, 75, 50, 50, 75,
400, 200, 50, 50, 75, 50, 50, 75,
400, 200, 50, 50, 75, 50, 50, 75,
75, 75, 250, 1000
};
int babySharkNotePause[] = {
50, 60, 25, 20, 25, 15, 25, 40,
50, 60, 25, 20, 25, 15, 25, 40,
50, 60, 25, 20, 25, 15, 25, 40,
30, 20, 50, 200
};
void songTask(void *p) {
TickType_t xLastWakeTime = 0 ;
const TickType_t xPeriod = pdMS_TO_TICKS(1000);
while(1) {
for (int i = 0; i < 28; i ++){
tone(babySharkOutput, babyShark[i], babySharkDuration[i]);
int songDelay = babySharkNotePause[i] * songSpeed;
vTaskDelay(songDelay);
}
vTaskDelayUntil( &xLastWakeTime, xPeriod);
}
}
void setup() {
pinMode(babySharkOutput, OUTPUT);
}
void loop() {
xTaskCreate(songTask, "songTask", STACK_SIZE, NULL, 1, NULL);
vTaskStartScheduler();
}
Hmm I expected this would run well because it can be run without the RTOS features, but there's something wrong here and I can't figure it out.
I use this c++ code
#include <iostream>
#include "parmetis.h"
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
int np = 3; int ne = 36;
idx_t *elmdist = new idx_t[np+1]; for (int i=0; i<np+1; i++) {elmdist[i] = (i-1)*ne/np;} elmdist[np] = ne;
idx_t *eptr = new idx_t[ne+1]; for (int i=0; i<ne+1; i++) {eptr[i] = (i-1)*3;}
idx_t eind_[] = {13, 14, 15,
13, 16, 17,
2, 17, 6,
4, 15, 10,
13, 15, 19,
13, 17, 18,
13, 19, 16,
13, 18, 14,
1, 5, 16,
3, 9, 14,
7, 8, 18,
11, 12, 19,
1, 20, 12,
3, 21, 8,
7, 18, 23,
11, 19, 22,
2, 23, 17,
4, 22, 15,
14, 25, 15,
16, 24, 17,
15, 22, 19,
17, 23, 18,
1, 16, 20,
3, 14, 21,
5, 24, 16,
9, 25, 14,
16, 19, 20,
14, 18, 21,
6, 17, 24,
10, 15, 25,
5, 6, 24,
9, 10, 25,
8, 21, 18,
12, 20, 19,
2, 7, 23,
4, 11, 22};
idx_t *eind = eind_;
idx_t *elmwgt = NULL;
idx_t wgtflag_[] = {0};
idx_t *wgtflag = wgtflag_;
idx_t numflag_[] = {0};
idx_t *numflag = numflag_;
idx_t ncon_[] = {1};
idx_t *ncon = ncon_;
idx_t ncommonnodes_[] = {2};
idx_t *ncommonnodes = ncommonnodes_;
idx_t nparts_[] = {np};
idx_t *nparts = nparts_;
real_t *tpwgts = new real_t[np*ncon[0]]; for(int i=0; i<np*ncon[0]; i++) {tpwgts[i] = 1.0/np;}
real_t ubvec_[] = {1.05};
real_t *ubvec = ubvec_;
idx_t options_[] ={0, 0, 0};
idx_t *options =options_;
idx_t *edgecut=NULL;
idx_t *part=NULL;
MPI_Comm *comm=NULL;
ParMETIS_V3_PartMeshKway(elmdist, eptr, eind, elmwgt, wgtflag, numflag, ncon, ncommonnodes, nparts, tpwgts, ubvec, options, edgecut, part, comm);
MPI_Finalize();
return 0;
}
In allmet I insert all files from metis and parmetis.
Try to compile using OpenMPI with g++ compiler:
mpicxx -I path/allmet/include -L path/allmet/lib par.cpp
I get error:
undefined reference to `ParMETIS_V3_PartMeshKway'
With cmake:
cmake_minimum_required(VERSION 2.8.9)
project (MetisTest)
find_package(MPI)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
include_directories("path/allmet/include")
link_directories("path/allmet/lib")
add_executable(metisTest par.cpp)
target_link_libraries(metisTest ${MPI_C_LIBRARIES})
I have:
undefined reference to `ParMETIS_V3_PartMeshKway'
in function `MPI::Intracomm::Intracomm()':
undefined reference to `MPI::Comm::Comm()'
and many others
So what I can do? Metis work perfect but with parmetis I can't do anything.
Ubuntu 18.10, gcc 8.2.0.
You also need to link against Parmetis itself:
target_link_libraries(metisTest ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PARMETIS_LIBS})
Do note that:
link_directories("path/allmet/lib")
Is irrelevant for the link. If you still want to use the command line, you need:
mpicxx -Ipath/allmet/include -Lpath/allmet/lib -lparmetis -lmetis par.cpp
pyhon matplot misses bars in bar graph. I expect it to generate bar at [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000] but it shows only at [250, 350, 450, 550, 650, 750]
import matplotlib.pyplot as plt
nsamples = 1000 + 1
vpp = 25
timestamps = [t for t in range(0, nsamples, vpp)]
processings = [0 for t in range(0, nsamples, vpp)]
transmissions = [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 650, 700, 750, 800, 850, 900, 950, 1000]
for transmission in transmissions:
processings[transmission / vpp] = 1
plt.bar(timestamps, processings)
plt.show()
OK. I got it working somehow and i don't know details but when i reduced the sample size by using range(0, nsamples/vpp, 1) instead of range(0, nsamples, vpp) then graph was plotted as expected (even though number of elements to be plotted against on x axis was still same.) it seems plt.bar assumes unit step between axis values in argument list instead of just taking the list itself and plotting it.
I have a rounded rectangle that I make like so
dc.RoundRect(textBorder, CPoint(20, 20));
Later on I draw a line through it about 1/3 of the way down.
dc.LineTo(textBorder.right, textBorder.top + 15);
Now I would like to fill just the part above the line with a solid color. In other words I need to fill a partially rounded rectangle, because the top of the rectangle is rounded, but the bottom of it is truncated by the line. Is there an easy way to do this?
Have you tried using a combination of CreateRoundRectRegion and then FillRgn to fill the non-rectangular area?
This the example given in the docs for CreateRoundRectRegion:
CRgn rgnA, rgnB, rgnC;
VERIFY(rgnA.CreateRoundRectRgn( 50, 50, 150, 150, 30, 30 ));
VERIFY(rgnB.CreateRoundRectRgn( 200, 75, 250, 125, 50, 50 ));
VERIFY(rgnC.CreateRectRgn( 0, 0, 50, 50 ));
int nCombineResult = rgnC.CombineRgn( &rgnA, &rgnB, RGN_OR );
ASSERT( nCombineResult != ERROR && nCombineResult != NULLREGION );
CBrush brA, brB, brC;
VERIFY(brA.CreateSolidBrush( RGB(255, 0, 0) ));
VERIFY(pDC->FillRgn( &rgnA, &brA)); // rgnA Red Filled
VERIFY(brB.CreateSolidBrush( RGB(0, 255, 0) ));
VERIFY(pDC->FillRgn( &rgnB, &brB)); // rgnB Green Filled
VERIFY(brC.CreateSolidBrush( RGB(0, 0, 255) )); // rgnC Blue
VERIFY(pDC->FrameRgn( &rgnC, &brC, 2, 2 ));
In general, when you want to do something with non-rectangular areas you have to start looking into regions.