I'm working on a project for my university. I'm connecting an Arduino to Max MSP using SimpleMessageSystem.
I read the values from the analog ports and it all works fine.
Although there is a metro 100 with the analog read to continue reading the values of it, as they change the whole time.
My problem is... that with the reading it also bangs every millisecond or so. But I would like that bang to stop after one of my analog reads, to play a sound when it reaches a specific number.
So what I want: I want ONE bang when the sensor reaches <340 if above 340 then 0.
I hope anyone can help and understand me.
I've managed it...
From the number value from my reading I split the outcome so I use:
split 0 340 and split 340 400
The first split with outcome message 1 and the second split message 0
You then use s num to select te number and r num to receive the number elsewhere.
You use change 666 and then select 0 1
And you connect your select to the toggle.
If it's an integer stream and you want one event triggered past 320 you could do:
[int] -> [> 340] -> [change] -> [sel 1]
The > 340 is because I don't know how consistent the integer stream is. Otherwise you could explicitly state the numbers to trigger once:
[int] -> [sel 340 ... ...]
This would create individual hard-coded patch cables for the events, refactoring that could be separate questions for the approach styles.
Related
I've recently started to learn about SUBLEQ One Instruction Set Computers and am currently trying to write a simple assembler for a SUBLEQ emulator i wrote. So far I've implemented DB, MOV, INC and DEC, but I am struggling a bit with the MOV instruction, when it has pointers as arguments.
For example: MOV 20, 21 to move data from address 21 to address 20 in SUBLEQ looks like this (assuming address 100 is zero and the program starts at address zero):
sble 20 20 3
sble 21 100 6
sble 100 20 9
The content at the target address is zeroed and the content at the source address is added to the destination by subtracting it two times.
Now to my problem: If one argument is a pointer, for example MOV 20, [21] so that the contents of address 21 are pointing to the real data I want to to copy to address 20, how can that be represented using SUBLEQ?
I'll start off by saying I know very little about how subleq is used in practice, so take this answer with a grain of salt:
One downside of subleq is that it is notoriously difficult to use pointers, but it can edit its own code. This means that you will have to use the code to rewrite the address being looked at with the value at 21.
for example, if you somehow got the code to go to a line appended after your current code you could use this:
# (I used the quotes to mean next line)
sble 3 3 " # set the first value of the second instruction to 0
sble 21 101 " # put the value of 21 into an unused address
sble 101 3 " # subtract the value of 101 and put it back into the code
sble 3 3 " # reset the value at 3 to 0
it might be a good decision to have to have a movp (move-pointer) command, so you don't accidentally mess up your mov command code at runtime
this means that a new method of using pointers has to be thought of differently for every problem someone comes across, but will usually be done by editing the code with the code
What is the logic of implementing truth table that do bitwise and of two inputs each is 4 bits or how many functions will be output i just need one example please .
You can use an online Python coding playground to find the answers to your truth table.
Here is a link for one: Python Online
Inside this you can play around with your inputs and then 'execute it' to see the output.
Here are two examples for you to type in. After you type this in, click 'execute' and wait for the results to appear on the right.
inputA = 0000
inputB = 0000
print(inputA & inputB)
>>> 0
inputA2 = 1110
inputB2 = 1111
print(inputA2 & inputB2)
>>> 1110
You can try to think of a more efficient way to find these values but for now you have a brute-force way to get all of the truth table values by manually changing them.
You can find other bitwise operations for Python here: Bitwise Operations
To answer the second part, if you have two 4 bit inputs, you can have up to 256 outputs (2^4 * 2^4)
My problem is that I am trying to make Controller using Arduino, ESP8266 SDcard module and some sensors. When I try to store some data in SDcard, at first time all works fine, but in second or third time I need to rewrite same line with different values. But there is an issue because line length is not equal with previous.
If it is longer then nothing wrong, but if shorter, then it will leave some unnecessary characters.
The most difficult part is where I need to store value of LED light and time:
255 10 0 Where 255 represents LED-value, 10-Hour, 0-min
Value can be 1 or 3 character long, hour 1 or 2, min 1 or 2...
So is there any solutions for this problem??
Now I am trying to change int to uint8_t to equal all possible values.
Is this approach Right? Maybe someone has made something like that?
Any suggestions will be appreciated.
You can normalize the data as you suggest so that the line length is always the same.
One approach is that all values are uint8_t which would require 3 uint8_t values.
Another is leave it as a string but each field is a fixed width with padded values. e.g. 0050901 for a value 5 at the 9th hour, 1st minute. Or pad with spaces so 5 9 1 for the same representation of this data. (Two spaces before the 5 and one space before the 9 and the 1).
Either approach is fine and just depends on what you prefer or what is easier when consuming and/or writing the data.
I have connected a device which sends data over a serial port, through UART and a usb connector.
On my laptop running ubuntu, I have written a C++ program to read this data and store it.
It sends 5 lines of 15 bites, 100 times per seconds, meaning: 500 lines per second.
I use the standard read command:
while((res += read(IMU, header, 15-res)) < 15);
string head(header, 15);
cout << indexLog << " " << head << endl;
when I read the serial port and read 15 bites it shows:
0 snp�` �����
0 snp�b#A��H
0 snp�dP�O�^���
0 snp�\����f
0 snp�^���e��M
0 snp�` �����
0 snp�b"����
where the snp is the beginning of each package. It can be seen that my laptop nicely reads every bite coming in, since every line starts with snp.
I would like to run the same application on my Raspberry PI, for weight and size considerations.
now when I run the same application on my raspberry PI, I get:
0 �Nsnp�Nsnp
0 Nsnp�\��
0 vsnp�^���
0 np�^�O�
0 vsnp�^�O�
0 np�^�D�
0 ssnp�
0 X�snp�dU
It looks like the raspberry doesn't read all the bites, and it becomes a big mess. Trying to salvage usefull date results in big data loss.
I all ready installed a skimmed down version of Rasbian, weezy. deinstalled X as GUI. But it doesn't seem to make difference.
I believe the raspberry should be fast enough.
What would be the limiting factor?
Is reading 500 lines (15 bites) per second over a serial just to much to cope with for the RasPI?
Are there any settings I can change or OS for the raspberry which can do the job better?
Or is there a way in C++ to read the data more efficient?
kind regards
Is reading 500 lines (15 bites) per second
That is 500 x 15 x 10 = 75000 bits per second. Clearly that is not possible when your baudrate is only 38400. So transmitter overrun is your first candidate for data loss.
You also have a fire-hose problem on the receiving end. Your terminal needs to be able to keep up with the rate, 500 lines per second is pretty challenging. Scrolling the window fast enough is the usual problem, not to mention the poor eyes of the user that needs to stare at this Matrix effect. This is the more likely source of the data loss, when you don't empty the serial port receive buffer quickly enough then you'll suffer from buffer overflow. It can also occur when the driver doesn't empty the UART fifo buffer quickly enough, less likely to be a problem at 38400 baud.
The obvious way ahead here is to improve your code so that you can actually detect these kind of errors so you know when it goes wrong.
I'm writing a server that sends a "coordinates buffer" of game objects to clients every 300ms. But I don't want to send the full data each time. For example, suppose I have an array with elements that change over time:
0 0 100 50 -100 -50 at time t
0 10 100 51 -101 -50 at time t + 300ms
You can see that only the 2nd, 4th, and 5th elements have changed.
What is the right way to send not all the elements, but only the delta? Ideally I'd like a function that returns the complete data the first time and empty data when there are no changes.
Thanks.
Are you looking to optimize for efficiency, or is this a learning exercise? Some thoughts:
Unless there's a lot of data, it's probably easiest, and not terribly inefficient, to send all the data each time.
If you send deltas for all of the data points each time, you won't save much by sending zeroes for unchanged points instead of re-sending the previous vales.
If you send data for only those points that change, you'll need to provide an index for each value. For example, if point 3 increases by 5 and point 8 decreases by 2, then you might send 3 5 8 -2. But now, since you're sending two values for each point that changes, you'll only win if fewer than half the points change.
If the values change relatively slowly, as compared to the rate at which you transmit updates, you might increase efficiency by transmitting the delta for each data point, but using only a few bits. For example, with 4 bits you can transmit values from -8 to +7. That would work as long as the deltas are never larger than that, or if it's ok to transmit several deltas before they "catch up" to the actual values.
It may not be worthwhile to have 2 different mechanisms: one to send the initial values, and another to send deltas. If you can tolerate the lag, it may make more sense to assume some constant initial value for every point, and then transmit only deltas.
There are lots of options. If most data isn't changing, just send (index,value) pairs of the changed elements. If most values change but the changes are small, compute deltas and gzip (or run length encode, or lots of other possibilities) the result.