Welcome Guest! To enable all features please Login or Register.
Options
Go to last post Go to first unread
JonnyAlsip@gmail.com  
#1 Posted : Saturday, May 16, 2015 4:28:07 PM(UTC)
JonnyAlsip@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/6/2015(UTC)
Posts: 9
United States

Was thanked: 1 time(s) in 1 post(s)
Hello,

I'm trying to create a node that will keep the date and time and spit out a text line for future nodes to use. I'm also trying to make it so I can change the date and time by inputting some text variables and a second code block connected to a trigger.

So ultimately I have the main code block that keeps the time based off a trigger connected to a timer and a second code block that resets the time variable when a second trigger is pressed. The problem seems to be though that when the second trigger is hit, it doesn't execute the second code block.

I don't know if I explained that well enough, but if anyone can provide some insight, it would be awesome.

Thanks,
AlsipianReefs Aquatics Controller: DIY Reef Controller
EmbrioAdmin  
#2 Posted : Saturday, May 16, 2015 4:29:22 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Can you copy and paste what you have into a reply? When you copy it saves as XML that I can paste into the software to see exactly what you're doing.
JonnyAlsip@gmail.com  
#3 Posted : Saturday, May 16, 2015 4:32:10 PM(UTC)
JonnyAlsip@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/6/2015(UTC)
Posts: 9
United States

Was thanked: 1 time(s) in 1 post(s)
<Nodes>
<Node>
<UniqueID>41a2cdd3-e864-498b-9651-787c5cfba7ce</UniqueID>
<AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType>
<NodeType>Custom Arduino Node</NodeType>
<UserDefinedName>DTG</UserDefinedName>
<Description>A node that lets you write any Arduino code to interact with the Arduino hardware. Can be both an input and output.</Description>
<NodeColor>201,204,227,255</NodeColor>
<X>0</X>
<Y>0</Y>
<Width>599</Width>
<IncludeCode></IncludeCode>
<DeclerationCode>String Time = &quot;000000000000&quot;;
String temp;
int sec;
int min;
int hour;
int day;
int mon;
int year;
boolean leapYear;</DeclerationCode>
<SetupCode>Time = Input_Year + Input_Month + Input_Day + Input_Hour + Input_Minute + &quot;00&quot;;
year = Input_Year.toInt();
mon = Input_Month.toInt();
day = Input_Day.toInt();
hour = Input_Hour.toInt();
min = Input_Minute.toInt();
sec = 0;</SetupCode>
<ImageName>arduino.png</ImageName>
<InfoURL></InfoURL>
<CodeDefinitions>
<CodeDefinition>
<TriggerInputID>1346c9f0-1c38-4648-902d-acbc9ac022fb</TriggerInputID>
<UpdateCondition>Trigger</UpdateCondition>
<Code>sec++;
if(year % 4 == 0) {
if(year % 100 == 0) {
if(year % 400 == 0) {
leapYear = true;
} else {
leapYear = false;
}
} else {
leapYear = true;
}
} else {
leapYear = false;
}
if(sec == 60) {
min++;
sec = 0;
}
if(min == 60) {
hour++;
hour = 0;
}
if(hour == 24) {
day++;
hour = 0;
}
if((mon == 1) || (mon == 3) || (mon == 5) || (mon == 7) || (mon == 8) || (mon == 10) || (mon == 12)) {
if(day == 32) {
mon++;
day = 1;
}
}
if((mon == 4) || (mon == 6) || (mon == 9) || (mon == 11)) {
if(day == 31) {
mon++;
day = 1;
}
}
if((leapYear) &amp;amp;&amp;amp; (mon == 2)) {
if(day == 30) {
mon++;
day = 1;
}
} else if((!leapYear) &amp;amp;&amp;amp; (mon == 2)) {
if(day == 29) {
mon++;
day = 1;
}
}
if(mon == 13) {
year++;
mon = 1;
}
Time = String(year);
if(mon &amp;lt; 10) {
Time += &amp;quot;0&amp;quot;+String(mon);
} else {
Time += String(mon);
}
if(day &amp;lt; 10) {
Time += &amp;quot;0&amp;quot;+String(day);
} else {
Time += String(day);
}
if(hour &amp;lt; 10) {
Time += &amp;quot;0&amp;quot;+String(hour);
} else {
Time += String(hour);
}
if(min &amp;lt; 10) {
Time += &amp;quot;0&amp;quot;+String(min);
} else {
Time += String(min);
}
if(sec &amp;lt; 10) {
Time += &amp;quot;0&amp;quot;+String(sec);
} else {
Time += String(sec);
}
Output_DTG = Time;</Code>
<UniqueID>b083b0fa-f743-4f58-ac3e-cf808311f895</UniqueID>
</CodeDefinition>
<CodeDefinition>
<TriggerInputID>c1771394-e6b9-4391-ac0a-225945687368</TriggerInputID>
<UpdateCondition>Trigger</UpdateCondition>
<Code>Time = Input_Year + Input_Month + Input_Day + Input_Hour + Input_Minute + &amp;quot;00&amp;quot;;
year = Input_Year.toInt();
mon = Input_Month.toInt();
day = Input_Day.toInt();
hour = Input_Hour.toInt();
min = Input_Minute.toInt();
sec = 0;
Output_DTG = Time;</Code>
<UniqueID>be3fc1f3-f143-4476-a54f-a28795ee1640</UniqueID>
</CodeDefinition>
</CodeDefinitions>
<Inputs>
<Input>
<UniqueID>1346c9f0-1c38-4648-902d-acbc9ac022fb</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Trigger</DefaultName>
<CustomName>1SEC Timer</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Trigger</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.TriggerNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs>
<Output>a052557c-4628-4e4b-9173-db4762c67d44</Output>
</ConnectedOutputs>
</Input>
<Input>
<UniqueID>907d6ece-ce29-4242-bb6f-2639cd8ad4a8</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Text</DefaultName>
<CustomName>Minute</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>String</TypeName>
<IsOutsideConnection>True</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.StringNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<DisconnectedValue>55</DisconnectedValue>
<MaxLength>2</MaxLength>
</Input>
<Input>
<UniqueID>8d2838bd-439f-49c2-8152-ee435cc941d4</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Text 1</DefaultName>
<CustomName>Hour</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>String</TypeName>
<IsOutsideConnection>True</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.StringNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<DisconnectedValue>07</DisconnectedValue>
<MaxLength>2</MaxLength>
</Input>
<Input>
<UniqueID>108b7b86-5acc-4bdd-95b1-443603b91d8b</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Text 2</DefaultName>
<CustomName>Day</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>String</TypeName>
<IsOutsideConnection>True</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.StringNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<DisconnectedValue>16</DisconnectedValue>
<MaxLength>2</MaxLength>
</Input>
<Input>
<UniqueID>9678ac5c-2360-4509-afbd-12bf3391f340</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Text 3</DefaultName>
<CustomName>Month</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>String</TypeName>
<IsOutsideConnection>True</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.StringNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<DisconnectedValue>05</DisconnectedValue>
<MaxLength>2</MaxLength>
</Input>
<Input>
<UniqueID>f55758f9-fbd1-4b8b-9465-fb8040240719</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Text 4</DefaultName>
<CustomName>Year</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>String</TypeName>
<IsOutsideConnection>True</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.StringNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<DisconnectedValue>2015</DisconnectedValue>
<MaxLength>4</MaxLength>
</Input>
<Input>
<UniqueID>c1771394-e6b9-4391-ac0a-225945687368</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Trigger 1</DefaultName>
<CustomName>Reset</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Trigger</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.TriggerNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
</Input>
</Inputs>
<Outputs>
<Output>
<UniqueID>ca8f0e55-7c49-42d9-950c-ca09c7a363a2</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Text</DefaultName>
<CustomName>DTG</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>String</TypeName>
<IsOutsideConnection>True</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.StringNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MaxLength>10</MaxLength>
</Output>
</Outputs>
</Node>
</Nodes>
AlsipianReefs Aquatics Controller: DIY Reef Controller
JonnyAlsip@gmail.com  
#4 Posted : Saturday, May 16, 2015 4:37:34 PM(UTC)
JonnyAlsip@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/6/2015(UTC)
Posts: 9
United States

Was thanked: 1 time(s) in 1 post(s)
So I think playing with the refresh rate fixes it. I had it at 32 and moved it to 64 which seems to work, but it's causing issues with some other components. I guess I need to play with it more.
AlsipianReefs Aquatics Controller: DIY Reef Controller
EmbrioAdmin  
#5 Posted : Saturday, May 16, 2015 4:45:00 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
You're getting into new territory for me. I don't know much about keeping actual clock time with an embedded processor but I'm worried that there will be enough drift to cause problems. Embrio is pretty darn accurate when it comes to running code over and over, say 64 times per second, but there will be some microseconds off each time which will add up. I think for accurate clock keeping you might need an external piece of hardware.

I'm also not sure about how you're using the text inputs for the time input pieces. This situation is starting to convince me that Embrio really does need other number input types than 0.0 to 1.0 activations, this seems like a pretty bad abuse of the text input. What exactly are you using this clock for?

If it's working for you that's great but I think there's some room for improvement here on Embrio's side. I've been really conflicted about the idea of adding other numeric input and output types but I'm starting to think it might be necessary, I hate to see people having to abuse text inputs like this to do what they are trying to do. I think I'll try an integer input/output type soon for situations like this.
JonnyAlsip@gmail.com  
#6 Posted : Saturday, May 16, 2015 5:03:51 PM(UTC)
JonnyAlsip@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/6/2015(UTC)
Posts: 9
United States

Was thanked: 1 time(s) in 1 post(s)
Yea, I would recommend some generic variables. Going only from 0 to 1 will work, but for some applications it becomes hard to convert back and forth between nodes if the information you're moving is different. The text variable seemed to be the best way to talk between nodes and be able to verify that everything was working correctly.

I'm trying to use this for a GUI on a TFT touchscreen as well as keeping track of what some other components are doing. I'm trying to control LEDs to mimic daylight so the time is important. I also have some outlet control and pump control which will work off basic switches. Lastly some inputs from some sensors.

Ultimately I've been building a reef controller for an aquarium. I have some of the basic functions working in the Arduino IDE, but the bigger this is getting, the more complicated and confusing the code is becoming especially when you have to go back an edit something. So Embrio looked almost perfect to compartmentalize everything and have things flow very well.

I am getting some funny results with what I have so far, some variables are triggering when they shouldn't be an it seems to be focused around the refresh rate. I'm trying to narrow it between bugs or my programming errors especially since I'm doing a lot of drafting.
AlsipianReefs Aquatics Controller: DIY Reef Controller
EmbrioAdmin  
#7 Posted : Saturday, May 16, 2015 5:09:08 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Yeah I used to think that when values came into Embrio they needed to be transformed from their native range to 0.0 to 1.0, then when they leave transformed back, but I'm realizing that there really are a lot of application where actual numbers will be useful in a program. It really doesn't make sense to convert from seconds to 0 to 1 and then back to seconds.

Like I said, you're doing something I haven't with custom Arduino nodes yet. These nodes pretty much just insert regular Arduino code into the compiled Embrio code, but with the wrapping of triggers and update events and such it's certainly possible that you're doing something right and Embrio is doing it wrong. If you find something please let me know so I can fix it. And of course if you figure out how to get it working please post it here for the record.
JonnyAlsip@gmail.com  
#8 Posted : Saturday, May 16, 2015 5:34:51 PM(UTC)
JonnyAlsip@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/6/2015(UTC)
Posts: 9
United States

Was thanked: 1 time(s) in 1 post(s)
I'll definitely be playing with it some more. Once I get a little further I'll post what I have.
AlsipianReefs Aquatics Controller: DIY Reef Controller
sugandh  
#9 Posted : Tuesday, June 09, 2015 2:05:59 AM(UTC)
sugandh

Rank: Newbie

Groups: Registered
Joined: 6/9/2015(UTC)
Posts: 1

Dear Friends

I am writing a C code for K-medoids (K-Mean) clustering in Linux and compiling this code on GCC compiler. Found following error by compiler


mp/cc4P1cED.o: In function `main':
k_medoid.c:(.text+0xa27): undefined reference to `getch'
k_medoid.c:(.text+0xbe4): undefined reference to `getch'
collect2: ld returned 1 exit status

My complete code is following

________________________________________________________________________________________

#include<stdio.h>
#include<math.h>
int distance(int [],int []);
int i,j,n,nc=3;
main()
{
int j,count,t;
int obj[10][2],c[10][10][2],mean[10][2],c1[10][10][2];
int i,k,m,cost=0,cost1;

//clrscr();

printf("n enter the no. of items:");
scanf("%d",&n);
printf("n enter the items(%d)",n);

for(i=0;i<n;i++)
for(j=0;j<2;j++)

scanf("%d",&obj[i][j]);

for(i=0;i<nc;i++)
for(j=0;j<n;j++)
for(k=0;k<2;k++)

{
c[i][j][k]=0;
c1[i][j][k]=0;
}

printf("n enter center points");
for(i=0;i<nc;i++)
for(j=0;j<2;j++)
{
scanf("%d",&mean[i][j]);
c[i][0][j]=mean[i][j];
}
j=0;
for(i=1;i<=n;i++)
{
if(j<n)
{

if(distance(obj[j],mean[0])<distance(obj[j],mean[1]))
if(distance(obj[j],mean[0])<distance(obj[j],mean[2]))
for(k=0;k<2;k++)
{
c[0][i][k]=obj[j][k];
cost=cost+distance(obj[j],mean[0]);
}

if(distance(obj[j],mean[1])<distance(obj[j],mean[0]))
if(distance(obj[j],mean[1])<distance(obj[j],mean[2]))
for(k=0;k<2;k++)
{
c[1][i][k]=obj[j][k];
cost=cost+distance(obj[j],mean[1]);
}

if(distance(obj[j],mean[2])<distance(obj[j],mean[0]))
if(distance(obj[j],mean[2])<distance(obj[j],mean[1]))
for(k=0;k<2;k++)
{
c[2][i][k]=obj[j][k];
cost=cost+distance(obj[j],mean[2]);
}
j++;
}
}

printf("n enter the next center points:");
for(i=0;i<nc;i++)
for(j=0;j<2;j++)
{
scanf("%d",&mean[i][j]);
c1[i][0][j]=mean[i][j];
}

j=0;
for(i=1;i<=n;i++)
{
if(j<n)
{
if(distance(obj[j],mean[0])<distance(obj[j],mean[1]))
if(distance(obj[j],mean[0])<distance(obj[j],mean[2]))
for(k=0;k<2;k++)
{
c1[0][i][k]=obj[j][k];
cost1=cost1+distance(obj[j],mean[0]);
}

if(distance(obj[j],mean[1])<distance(obj[j],mean[0]))
if(distance(obj[j],mean[1])<distance(obj[j],mean[2]))
for(k=0;k<2;k++)

{
c1[1][i][k]=obj[j][k];
cost1=cost1+distance(obj[j],mean[1]);
}

if(distance(obj[j],mean[2])<distance(obj[j],mean[0]))
if(distance(obj[j],mean[2])<distance(obj[j],mean[1]))
for(k=0;k<2;k++)
{
c[2][i][k]=obj[j][k];
cost1=cost1+distance(obj[j],mean[2]);
}
j++;
}
}

getch();

if(cost<cost1)
{
for(i=0;i<nc;i++)
{

printf("n");
for(j=0;j<n;j++)
for(k=0;k<2;k++)
{
if(c[i][j][k]>0)

printf("%dt",c[i][j][k]);
}
}
}
else
{
for(i=0;i<nc;i++)
{

printf("n");
for(j=0;j<n;j++)
for(k=0;k<2;k++)
{
if(c1[i][j][k]>0)
printf("%dt",c1[i][j][k]);
}
}
}

getch();

}
int distance(int obj[],int mean[])
{
int x1,x2,y1,y2,dist;

x1=obj[0];
x2=mean[0];
y1=obj[1];
y2=mean[1];
dist=(sqrt(pow((x1-x2),2)+pow((y1-y2),2)));
return dist;
}


Please Dear friends write a valuable comments. I am waiting for your good suggestion and valuable Love Love
JonnyAlsip@gmail.com  
#10 Posted : Tuesday, June 09, 2015 2:47:07 AM(UTC)
JonnyAlsip@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/6/2015(UTC)
Posts: 9
United States

Was thanked: 1 time(s) in 1 post(s)
Your best bet is to look around Arduino.cc instead of here.

But you're getting that error because it's trying to find the function 'getch()' when it doesn't exist. This looks like an older code example. Math.h is usually already included in the Arduino IDE and I believe stdio.h has been updated if it's even used anymore. Like I said, you're best bet is looking through the forums at Arduino.cc

Arduino Forum - Programming Questions

This might help too:
Getch to Getchar

I changed the 'getch()'s to 'getchar()'s and it compiled correctly.

Edited by user Tuesday, June 09, 2015 2:51:33 AM(UTC)  | Reason: Got more info

AlsipianReefs Aquatics Controller: DIY Reef Controller
thanks 1 user thanked JonnyAlsip@gmail.com for this useful post.
EmbrioAdmin on 6/9/2015(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error