Is there any way to pass/ select a output through a function? - function

I am controlling 4 led using the arduino using millis. I am trying to get the control the same section through 1 generic code and load in variables like what output pin to control. watching through serial I can see it is analogWrite(13, 255) however the pin does nothing.
void led_script_effect(......, int red_output , int green_output, int blue_output)
where
led_script_effect(red_wanted = red_wanted_strip_1, green_wanted = green_wanted_strip_1, blue_wanted = blue_wanted_strip_1)
What would be the correct argument to pass in a valid pin output or would the output have to be returned and then within the loop be analog write?

The reason analogWrite(13,255) is not working for you is because, pin 13 is NOT a PWM pin.
Read more about it in the link below:
https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
The use of the sentence 'I am controlling 4 led using the Arduino using millis.' threw me off, but then I realized that you are using the generic function for PWM control on Arduino.
I really think you would benefit from the Arduino code in the Hackster project below:
https://www.hackster.io/devashish-gupta/controlling-led-brightness-using-bolt-and-arduino-2041b9

Related

object notation in verilog

I am newbie to verilog hdl.
For testing a single cycle mips cpu, I am trying to use the following notation to initialize a register from the testbench.
CPU.IM.memory[i] = 32'b0
Here, CPU is one module which has a declaration for IM (another module) and memory is declared as a reg in it.
However, the Quartus verilog compiler is complaining that it cannot find the object reference. Is the above supported? I have a similiar problem in loading instructions in memory, I dont want to be able to do it from the testbench, instead of hardcoding or changing it in IM.
TestBench.v
for(i = 0; i < 32; i = i + 1) begin
CPU.IM.IMReg[i] = 32'b0;
end
CPU.v
IM IM(
//inputs
.address (pc),
.clk (clk),
.out (Instruction)
);
IM.v
module IM ( address, clk, out);
input [31:0] address;
input clk;
output reg[31:0] out;
reg[31:0] IMReg[31:0];
Error being thrown
Error (10207): Verilog HDL error at TestBench.v(31): can't resolve reference to object "IMReg"
It's hard to tell what you're trying to do without seeing more of your code, but what I'm guessing is that you're trying to assign an internal signal (ie a signal not present on the input or output port list) of a module a value from inside a different module. Unless that value is a constant parameter, you can't do this. Only parameters, localparams, and signals on the port list (inputs, outputs, and inouts) are externally visible.
Usually, memories are initialized off of either a .hex or .mif file, which can be altered to represent the desired initial state.

How to use Eiffel functions?

So I'm just starting to learn Eiffel. One of the first exercises in the book I'm using says to make a function that does base^exp without using ^. I've copied my code below.
class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
make
-- Run application.
do
create power(2;3)
printf("2 to the power of 3 is " + answer)
end
power(base : REAL; exp : INTEGER) : REAL
-- computers base raised to the bower of exp without using ^
local
remain : INTEGER
do
remain := exp
if remain = 0 then
result := 1
else
from
until
remain = 0
loop
result := result * result
remain := remain -1
end
end
end
end
How do I use this? Do I need it on the same level as feature{NONE}'s make? I know how I'm calling it is wrong, and I can't find anything in the chapter I just read, or online on how to pass parameters into it or how to use it's results.
There are several issues with the original code:
create is used to create an object, but you are not going to create anything, but to get a result of a computation of the function power by calling it. Therefore the keyword create is not needed.
You are using an entity answer to report the result of evaluation on a screen. However it is not declared anywhere. I believe the proper place would be a local variable declaration section.
The entity answer is not initialized to the result of the function power. This is usually done by an assignment instruction.
Feature arguments are separated by a comma, not by a semicolon.
From the original code it's unclear what is the type of the variable answer. Assuming it matches the type of the function power, before adding it to a string, it needs to be converted to a string. This is done by calling the feature out.
The standard feature for printing a string to a console is print, not printf.
Combining the critical points above, we get
make
-- Run application.
local
answer: REAL
do
answer := power(2, 3)
print ("2 to the power of 3 is " + answer.out)
end
After that the code can be compiled. Now less critical points:
It is a good style to put features to a dedicated feature clauses, so I would add a line like feature -- Basic operations before the feature power.
The implementation of the feature power has at least two problems. I'm not going to detail them here, but would give two hints instead:
by default numeric Result is initialized to 0, this needs to be taken into account for operations that use it without first assigning any other value
even though an argument base is passed to the function power it remains unused in the original version of the code

Understanding heisenbug example: "Debuggers cause additional source code to be executed stealthily"

I read wikipedia page about heisunbug, but don't understand this example. Can anyone explain it in detail?
Debuggers also commonly provide watches or other user interfaces that cause additional source code (such as property accessors) to be executed stealthily, which can, in turn, change the state of the program.
I think what it's getting at is that the debugger itself may call code (such as getters) to retrieve the value of a property you might have placed a watch on.
Consider the getter:
def getter fahrenheit:
return celsius * 9 / 5 + 32;
and what would happen if you put a watch on the fahrenheit property.
That code would normally only be called if your code itself tried to access the fahrenheit propery but, if a debugger is calling it to maintain the watch, it may be called outside of the control of your program.
A simple example, let's say the getter has a (pretty obvious) bug which means that it returns the wrong result the first time it's called:
class temperature:
variable state
def init:
state = 1
def getter fahrenheit:
if state == 1:
state = 0
return -42
return celsius * 9 / 5 + 32;
So running your code without a debugger exhibits a problem in that it will return a weird value the first time your code calls it.
But, if your debugger is actually calling the getter to extract a value that it's watching (and it's probably doing this after every single-step operation you perform), that means the getter will be well and truly returning the correct value by the time your code calls it for what it thinks is the first time.
Hence the problem will disappear when you try to look closer at it, and that's the very definition of a Heisenbug, despite the fact that Heisenberg's actual uncertainty principle has little to do with the observer effect.

Append string to a Flash AS3 shared object: For science

So I have a little flash app I made for an experiment where users interact with the app in a lab, and the lab logs the interactions.
The app currently traces a timestamp and a string when the user interacts, it's a useful little data log in the console:
trace(Object(root).my_date + ": User selected the cupcake.");
But I need to move away from using traces that show up in the debug console, because it won't work outside of the developer environment of Flash CS6.
I want to make a log, instead, in a SO ("Shared Object", the little locally saved Flash cookies.) Ya' know, one of these deals:
submit.addEventListener("mouseDown", sendData)
function sendData(evt:Event){
{
so = SharedObject.getLocal("experimentalflashcookieWOWCOOL")
so.data.Title = Title.text
so.data.Comments = Comments.text
so.data.Image = Image.text
so.flush()
}
I don't want to create any kind of architecture or server interaction, just append my timestamps and strings to an SO. Screw complexity! I intend to use all 100kb of the SO allocation with pride!
But I have absolutely no clue how to append data to the shared object. (Cough)
Any ideas how I could create a log file out of a shared object? I'll be logging about 200 lines per so it'd be awkward to generate new variable names for each line then save the variable after 4 hours of use. Appending to a single variable would be awesome.
You could just replace your so.data.Title line with this:
so.data.Title = (so.data.Title is String) ? so.data.Title + Title.text : Title.text; //check whether so.data.Title is a String, if it is append to it, if not, overwrite it/set it
Please consider not using capitalized first letter for instance names (as in Title). In Actionscript (and most C based languages) instance names / variables are usually written with lowercase first letter.

ref keyword with C++/CLI code interface

I'm writing code for the Windows Phone 8, and I'm trying to learn the ins and outs of crossing the C#/C++ code barrier.
Let's say I have two float[] arrays on the C# side, we'll call them data1 and data2. I want to perform an element-by-element addition on them. As this is in a realtime system, (audio processing) I don't want to risk doing allocations and deallocations inside my audio processing routines, so I'll want something along the lines of data1[i] += data2[i]. Since I'm explicitly learning how to call C++ from C# though, I won't just write the for loop in C#, I will write it in C++, like so:
void LibFilter::mixIn( Platform::Array<float>^ * data1, const Platform::Array<float>^ data2 ) {
auto outArray = (*data1);
// Don't do anything if we don't have matching lengths
if( data2->Length != outArray->Length )
return;
// Sum data2 into outArray (which is just a dereferenced data1)
for( unsigned int i=0; i<outArray->Length; ++i ) {
outArray[i] += data2[i];
}
}
This seems like it should work to me, but then again, I'm a C++ programmer, not a C# programmer, and apparently this should be used with the out keyword in C#, which means that data1 is a null pointer, no matter the value passed in. I believe I want to use the ref keyword instead, but I can't figure out how to do that using the Windows Phone 8 SDK.
Suggestions on how to use the ref keyword here, or how best to architect this would be much appreciated, as I am still learning best practices with C#. Thank you all!
EDIT: Error information
If I just try to use libfilter.mixIn( ref data1, data2 ); from my C# code, I get the following:
error CS1502: The best overloaded method match for 'libfilter.LibFilter.mixIn(out float[], float[])' has some invalid arguments
error CS1620: Argument 1 must be passed with the 'out' keyword
Based on your edit, it seems that the metadata that the C++/CX compiler generates for the method uses the out keyword, not the ref keyword.
Anyway, I don't see why you need to pass by reference at all. Platform::Array is mutable, so you can just modify it even if it's passed by value. The following MSDN article has an example similar to your code (see the section "Fill arrays"):
http://msdn.microsoft.com/en-us/library/windows/apps/hh700131.aspx